//
//  HomeViewController.m
//  W2MD
//
//  Created by zhudongwei on 14-9-15.
//  Copyright (c) 2014年 zhudongwei. All rights reserved.
//

#import "HomeViewController.h"
#import "ContentCollectionViewCell.h"
#import "HomeViewFlowLayout.h"
#import "HomeWaterfallHeaderReusableView.h"
#import "HomeWaterfallDecorationReusableView.h"
#import "NetWebServiceRequest.h"
#import "Constant.h"
#import "UIImageView+WebCache.h"
#import "Type01.h"
#import "Type02.h"
#import "SecListCollectionViewCell.h"
#import "DetailViewShow.h"
#import "HomeDetailViewController.h"
#import "MenuView.h"
#import "FilterView.h"
#import "FilterLevel2View.h"
#import "FilterLevel3CollectionViewCell.h"
#import "thirdLib/fmdb/FMDB.h"
#import <sqlite3.h>
#import "KuanShiTableViewController.h"
#import "DetailColorCollectionViewCell.h"
#import "LoadingView.h"
#import "StartAnimationViewController.h"
#import "HelpView.h"
#import "Utility.h"
#import "SXModel.h"
#import "Reachability.h"
#import "UIImage+MostColor.h"
#import "SecMCollectionViewCell.h"

#define BGColor [[UIColor alloc] initWithRed:0.f green:0.f blue:0.f alpha:0.3];
#define HGColor [[UIColor alloc] initWithRed:0.f green:0.f blue:0.f alpha:0.9];
#define DefaultCornerRadius 8.f

#define ImageUrl @"http://115.28.80.218/downloadImg/";
#define DefaultCostumeID @"4"
#define DefaultColorCode @"#FF0000"


@interface UIImage(Overlay)
@end

@implementation UIImage(Overlay)

//- (UIImage *)imageWithColor1:(UIColor *)color1
//{
//    UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    CGContextTranslateCTM(context, 0, self.size.height);
//    CGContextScaleCTM(context, 1.0, -1.0);
//    CGContextSetBlendMode(context, kCGBlendModeNormal);
//    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
//    CGContextClipToMask(context, rect, self.CGImage);
//    [color1 setFill];
//    CGContextFillRect(context, rect);
//    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return newImage;
//}
@end

typedef enum _ViewType
{
    EM_VT_Home,
    EM_VT_Filter
}ViewType;

typedef enum _MenuTopType
{
    EM_MTT_NONE,
    EM_MTT_top1,
    EM_MTT_top2
}MenuTopType;

typedef enum _FilterViewType
{
    EM_FVT_NONE,
    EM_FVT_top2,
    EM_FVT_top3
}FilterViewType;

typedef enum _SearchType
{
    EM_ST_NONE,
    EM_ST_New,
    EM_ST_Default,
    EM_ST_Add,
    EM_ST_LoadMore,
}SearchType;

typedef enum _TopOneType
{
    EM_TOT_NONE=0,
    EM_TOT_Maozi=1,
    EM_TOT_Yanjing=2,
    EM_TOT_Pidai=3,
    EM_TOT_Top1=4,
    EM_TOT_Kuzi=5,
    EM_TOT_Qunzi=6,
    EM_TOT_Liantizhuang=7,
    EM_TOT_Baobao=8,
    EM_TOT_Wazi=9,
    EM_TOT_Xiezi=10,
    EM_TOT_TOP2=12,
    EM_TOT_top3=13,
}TopOneType;

static NSString* const WaterfallCellIdentifier = @"WaterfallCell";
static NSString* const WaterfallHeaderIdentifier = @"WaterfallHeader";
static NSString *kCellID = @"cellID";
static NSString *kSecListCellID = @"SecListCellID";
static NSString *kLevel3CellID = @"Level3CellID";
static NSString *kLevel4CellID = @"Level4CellID";
static NSString *kLevel5CellID = @"Level5CellID";
static NSString *kLevel6CellID = @"Level6CellID";
static NSString *kLevel7CellID = @"Level7CellID";
static NSString *kLevel8CellID = @"Level8CellID";

static NSString *TopValuesKey = @"topValuesCell";

@interface HomeViewController ()<HomeViewWaterfallCollectionViewDelegate,UICollectionViewDelegate,
                                    NetWebServiceRequestDelegate,UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,MenuDelegate>
{
    FilterType m_filtertype;
    FilterSubmenuType m_filterSubmenutype;
    FilterSubmenuType selectedSubtype;
    MenuTopType menuTopType;
    NSString *path;
    NSMutableDictionary *top2KeyValue;
    TopOneType  topOneType;
    NSString *topTwoValue;
    //FilterLevel2View * filterLevel2View;
    FilterViewType filterViewType;
    int colorIndex;
    NSMutableDictionary *ColorThdKeyValue;
    NSMutableDictionary *ColorThdKeyValueB;
    NSMutableDictionary *ColorThdKeyValueA;
    NSMutableDictionary *topKeyValue;
    NSMutableDictionary *secKeyValue;
    NSString* kuanshi1tvChoiceKey;
    
    NSMutableDictionary *SearchDic;
    FilterView *filerDetailView;
    ViewType viewType;
    //int checkint;
    NSMutableDictionary *yanseDic;
    NSMutableDictionary *wenziDic;
    
    UIButton *filerBtn;
    BOOL isLeftBtnHistory;
    //BOOL isDefaultFetch;
    
    int totalNum;
    int totalpage;
    int currentpage;

    LoadingView *lv;
    NSUserDefaults *userDefaults;
    BOOL isHomeSearch;
    BOOL isNewSearch;
    BOOL isFetchData;
    BOOL isAddSearch;
    SearchType searchType;
    
    int defaultSearchIndex;
    NSString *cumtomerID;
    NSString *colorID;
    
}
@property (nonatomic, strong) HomeViewFlowLayout *layout;
@property (nonatomic, strong) NSMutableArray *cellHeights;
@property (nonatomic, strong) NetWebServiceRequest* runningRequest;
@property (nonatomic, strong) NetWebServiceRequest* gettingRequest;
@property (nonatomic, strong) NSMutableArray *infoArrays;
@property (nonatomic, strong) UICollectionView *level2CV;
@property (nonatomic, strong) NSMutableArray *level2CVinfoArrays;
@property (nonatomic, strong) UITableView *level3TV;
@property (nonatomic, strong) NSMutableDictionary *level3CVinfodic;
@property (nonatomic, strong) NSMutableArray *filterLevel3CVinfoArrays;
@property (nonatomic, strong) NSMutableArray *filterLevel5CVinfoArrays;
@property (nonatomic, strong) UICollectionView *filterLevel2CV;
@property (nonatomic, strong) NSMutableArray *filterLevel2CVinfoArrays;
@property (nonatomic, strong) UICollectionView *filterLevel3CV;
@property (nonatomic, strong) UICollectionView *filterLevel3CAno;
@property (nonatomic, strong) UICollectionView *filterLevel3CBef;
@property (nonatomic, strong) UICollectionView *filterLevel4CV;
@property (nonatomic, strong) UICollectionView *filterLevel4CAno;
@property (nonatomic, strong) UICollectionView *filterLevel4CBef;

@property (nonatomic,assign) FilterSubmenuType m_fst;
@property (nonatomic,strong) NSDateComponents *comps;
@property (nonatomic,strong) Reachability *internetReachability;
@property (nonatomic,strong) Reachability *wifiReachability;
@property (nonatomic,strong) NSMutableArray *defaultImgArr;

@property(nonatomic, strong) UITableView *kuanshi1tv;
@property(nonatomic, strong) UITableView *kuanshi2tv;

@end


@implementation HomeViewController
//-(UIImage*) imageWithColor:(UIColor*)color
//{
//    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
//    UIGraphicsBeginImageContext(rect.size);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    
//    CGContextSetFillColorWithColor(context, [color CGColor]);
//    CGContextFillRect(context, rect);
//    
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    
//    return image;
//}

- (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}

- (BOOL) IsLessThanIphone5 {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);
            if(result.height == 960)
            {
                return YES;
            }
            return NO;
        }
    }
    return NO;
}
/*
 CGRect rect = [[UIScreen mainScreen] bounds];
 CGSize size = rect.size;
 CGFloat width = size.width;
 CGFloat height = size.height;
*/

#pragma mark - UIPickerView
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    SXModel *model=[SXModel shareModel];
    switch (component) { // component是栏目index，从0开始，后面的row也一样是从0开始
        case 0: { // 第一栏为hour
            return model.timeArr.count;
        }
            break;
        case 1: // 第二栏为minute
            return model.hourArr.count*50;
            break;
        case 2:
            return model.minuteArr.count*50;
            break;
        default:
            return 0;
            break;
    }
    
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    SXModel *model=[SXModel shareModel];
    switch (component) {
        case 0:
            return [model.timeArr objectAtIndex:row];
            break;
        case 1:
            return [model.hourArr objectAtIndex:row%model.hourArr.count];
            break;
        case 2:
            return [model.minuteArr objectAtIndex:row%model.minuteArr.count];
            break;
        default:
            return 0;
            break;
    }
    
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    //NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    switch (component) {
        case 0: {
            NSLog(@"row=%d",(int)row);
            [self pickerViewLoaded:0];
            break;
        }
        case 1: {
            NSLog(@"row=%d",(int)row);
            [self pickerViewLoaded:1];
            break;
        }
        case 2: {
            NSLog(@"row=%d",(int)row);
            [self pickerViewLoaded:2];
            break;
        }
        default:
            break;
    }
    //[pickerView reloadAllComponents]; // 注意，这一句不能掉，否则选择后每一栏的数据不会重载，其作用与UITableView中的reloadData相似
}

-(void)pickerViewLoaded:(int)which
{
    NSUInteger max=0;
    NSUInteger base=0;
    SXModel *model=[SXModel shareModel];
    if (which==1) {
        max = model.hourArr.count*50;
        base = (max/2)-(max/2)%24;
        [self.datePicker selectRow:[self.datePicker selectedRowInComponent:which]%24+base inComponent:which animated:false];
        model.hourIndex=[self.datePicker selectedRowInComponent:which]%24+base;
        if (self.hourIndex!=model.hourIndex) {
            self.hourIndex=model.hourIndex;
            if ([self.datePicker selectedRowInComponent:which]%24>11 && [self.datePicker selectedRowInComponent:which]%24<24) {
                model.timeIndex=1;
            } else
                model.timeIndex=0;
            [self.datePicker selectRow:model.timeIndex inComponent:0 animated:YES];
        }
        
    } else if (which==2) {
        max = model.minuteArr.count*50;
        base = (max/2)-(max/2)%60;
        [self.datePicker selectRow:[self.datePicker selectedRowInComponent:which]%60+base inComponent:which animated:false];
        model.minuteIndex=[self.datePicker selectedRowInComponent:which]%60+base;
        NSLog(@"!!!!!=%ld",(long)model.minuteIndex);
        
    } else if (which==0) {
        model.timeIndex=[self.datePicker selectedRowInComponent:0];
        if (model.timeIndex==0 && model.hourIndex-600>11) {
            model.hourIndex=model.hourIndex-12;
            [self.datePicker selectRow:model.hourIndex inComponent:1 animated:NO];
        } else if (model.timeIndex==1 && model.hourIndex-600<12) {
            model.hourIndex=model.hourIndex+12;
            [self.datePicker selectRow:model.hourIndex inComponent:1 animated:NO];
        }
    }
}

- (void)calculateClock
{
    SXModel *model=[SXModel shareModel];
    NSDate *date=[NSDate date];
    NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *dateComp=[calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:date];
    //当前的时间
    //获取系统是24小时制或者12小时制
    //NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
    //NSRange containsA = [formatStringForHours rangeOfString:@"a"];
    //BOOL hasAMPM = containsA.location != NSNotFound;
    //hasAMPM==TURE为12小时制，否则为24小时制
   
    NSString *dateStr1=[[NSString alloc] init];
    //if (hasAMPM) {
        NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"HH:mm:ss"]; // 这里是用大写的H就是24小时制
        dateStr1 = [dateFormatter stringFromDate:date];
        NSLog(@"date1=%@",dateStr1);
//        [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; // 这里是用大写的H就是24小时制
//        NSString* dateStr2 = [dateFormatter stringFromDate:date];
//        NSLog(@"date2=%@",dateStr2);
    //}
    NSInteger hour=[[dateStr1 substringToIndex:2] integerValue];
    NSInteger minute=[dateComp minute];
    NSInteger second=[[dateStr1 substringFromIndex:6] integerValue];
    NSInteger currentTotal=hour*3600+minute*60+second;
    //NSLog(@"now=%ld",(long)hour);
    //闹钟的时间
    NSInteger clockHour=model.hourIndex-600;
    NSInteger clockMinute=model.minuteIndex-1500;
    NSInteger clockTotal=clockHour*3600+clockMinute*60;
    NSLog(@"model.hour=%d,minute=%d",(int)model.hourIndex,(int)model.minuteIndex);
    
    //通知的时间
    //NSInteger alarmTime=clockTotal-currentTotal;
    NSLog(@"clockTotal=%ld,currentTotal=%ld",(long)clockTotal,(long)currentTotal);
    NSString *todayWeek=[self weekDayStr];//今天是周几
    NSLog(@"todayWeek=%@",todayWeek);
    int todayIndex=0;
    for (int i=0; i<self.weekSArr.count; i++) {//判断今天的数组位置
        if ([todayWeek isEqualToString:[self.weekSArr objectAtIndex:i]]) {
            todayIndex=i;
        }
    }
    if (model.weekArr.count==0) {//如果还没到，就今天响，如果过了，就第二天响
        NSInteger alarmTime=clockTotal-currentTotal;
        if (alarmTime>=0) {
            NSLog(@"今天就响");
            [self notificationClock:alarmTime];
        } else {
            NSLog(@"明天响");
            alarmTime=alarmTime+24*3600;
            [self notificationClock:alarmTime];
        }
        
    } else {
        NSMutableArray *indexArr=[[NSMutableArray alloc] init];
        for (int i=0; i<model.weekArr.count; i++) {
            NSString *week=[model.weekArr objectAtIndex:i];
            for (int j=0; j<self.weekSArr.count; j++) {//判断设定的星期的数组位置
                if ([week isEqualToString:[self.weekSArr objectAtIndex:j]]) {
                    [indexArr addObject:[NSString stringWithFormat:@"%d",j]];
                }
            }
        }
        for (int i=0; i<indexArr.count; i++) {
            int index=[[indexArr objectAtIndex:i] intValue];
            if (index==todayIndex) {//包含今天
                NSInteger alarmTime=clockTotal-currentTotal;
                if (alarmTime>=0) {
                    NSLog(@"今天就响");
                    [self notificationClock:alarmTime];
                } else {
                    NSLog(@"下周的今天响");
                    alarmTime=alarmTime+7*24*3600;
                    [self notificationClock:alarmTime];
                }
            } else {//包含不是今天的
                NSInteger alarmTime=clockTotal-currentTotal;
                if (index-todayIndex>=0) {
                    alarmTime=alarmTime+(index-todayIndex)*24*3600;
                } else {
                    alarmTime=alarmTime+(7+index-todayIndex)*24*3600;
                }
                [self notificationClock:alarmTime];
            }
        }
    }
    
    
    [self backToClockTable];
}

- (NSString*)weekDayStr
{
    NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];
    NSDate *date = [NSDate date];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit |
    NSMonthCalendarUnit |
    NSDayCalendarUnit |
    NSWeekdayCalendarUnit |
    NSHourCalendarUnit |
    NSMinuteCalendarUnit |
    NSSecondCalendarUnit;
    comps = [calendar components:unitFlags fromDate:date];
    int week = (int)[comps weekday];
    return [arrWeek objectAtIndex:week-1];
}

- (void)notificationClock:(NSInteger)addTime
{
    //1、增加一个本地推送
    
    //设置20秒之后
    
    NSDate *date = [NSDate new];
    
    //chuagjian一个本地推送
    
    UILocalNotification *noti = [[UILocalNotification alloc] init];
    
    static int sum=0;
    static NSMutableArray *notiArr;
    
    if (noti) {
        
        //设置推送时间
        
        noti.fireDate = [date dateByAddingTimeInterval:addTime];
        
        //设置时区
        
        noti.timeZone = [NSTimeZone defaultTimeZone];
        
        //设置重复间隔
        
        noti.repeatInterval = kCFCalendarUnitWeek;
        
        //推送声音
        
        //noti.soundName = UILocalNotificationDefaultSoundName;
        //noti.soundName=[[NSBundle mainBundle] pathForResource:@"summer" ofType:@"caf"];
        noti.soundName=@"summer.mp3";
        
        //右上角消息个数
        noti.applicationIconBadgeNumber++;
        
        //内容
        
        noti.alertBody = @"哈喽";
        noti.alertAction= NSLocalizedString(@"起床了", nil);
        
        //显示在icon上的红色圈中的数子
        
        noti.applicationIconBadgeNumber = 1;
        
        //设置userinfo 方便在之后需要撤销的时候使用
        SXModel *model=[SXModel shareModel];
        
        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%ld:%ld",(long)model.hourIndex,(long)model.minuteIndex] forKey:@"key"];
        
        noti.userInfo = infoDic;
        
        
        NSMutableDictionary *notiDic=[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:noti],@"NOTI",@"YES",@"ONOFF",nil];
        
        if (![userDefaults valueForKey:@"showWel1.0"]) {//如果是第一次设定的默认闹钟，把开关关掉
            [notiDic setValue:@"NO" forKey:@"ONOFF"];
        } else {
            //添加推送到uiapplication
            UIApplication *app = [UIApplication sharedApplication];
            
            [app scheduleLocalNotification:noti];
            
            //[NSTimer scheduledTimerWithTimeInterval:addTime target:self selector:@selector(clockPlayer) userInfo:nil repeats:NO];
            
//            __block    UIBackgroundTaskIdentifier bgTask;
//            bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    if (bgTask != UIBackgroundTaskInvalid)
//                    {
//                        bgTask = UIBackgroundTaskInvalid;
//                    }
//                });
//            }];
//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    if (bgTask != UIBackgroundTaskInvalid)
//                    {
//                        bgTask = UIBackgroundTaskInvalid;
//                    }
//                });
//            });
            
        }
        
        
        if (!self.notiArr) {
            notiArr=[[NSMutableArray alloc] init];
            self.notiArr=YES;
        }
        [notiArr addObject:notiDic];
        sum++;
        //UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        
        if (model.weekArr.count!=0) {
            if (sum==model.weekArr.count) {
        
//                if ([userDefaults valueForKey:@"showWel1.0"] && [[notiDic valueForKey:@"ONOFF"] boolValue]) {
//                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"通知"
//                                                                    message:@"闹钟设定成功"
//                                                                   delegate:self
//                                                          cancelButtonTitle:@"确定"
//                                                          otherButtonTitles:nil];
//                    [alert show];
//                }
                
                sum=0;
                if (!model.changeClock) {
                    [model.localNotiArr addObject:notiArr];
                } else {
                    [model.localNotiArr insertObject:notiArr atIndex:model.deleteIndex];
                }
                
                //NSLog(@"modelLocal!!!=%@",model.localNotiArr);
                //NSLog(@"segindexArr!!!=%@",model.segIndexArr);
                //NSLog(@"notification!!!=%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
                [[NSUserDefaults standardUserDefaults] setObject:model.localNotiArr forKey:@"NOTIARR"];
                self.notiArr=NO;
                NSLog(@"111222");
            }
            
        } else {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"通知"
//                                                            message:@"闹钟设定成功"
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:nil];
//            [alert show];
            sum=0;
            if (!model.changeClock) {
                [model.localNotiArr addObject:notiArr];
            } else {
                [model.localNotiArr insertObject:notiArr atIndex:model.deleteIndex];
            }
            [[NSUserDefaults standardUserDefaults] setObject:model.localNotiArr forKey:@"NOTIARR"];
            self.notiArr=NO;
            NSLog(@"111222");
        }
        
        
    }
}

- (void)backToClockTable
{
    //闹钟时间
    SXModel *model=[SXModel shareModel];
    NSInteger clockHour=model.hourIndex-600;
    NSString *hour=[NSString stringWithFormat:@"%ld",(long)clockHour]
    ;
    if (clockHour<10) {
        hour=[NSString stringWithFormat:@"0%ld",(long)clockHour];
    } else if (clockHour>12){
        if (clockHour-12<10) {
            hour=[NSString stringWithFormat:@"0%ld",(long)(clockHour-12)];
        } else
            hour=[NSString stringWithFormat:@"%ld",(long)(clockHour-12)];
    }
    
    NSInteger clockMinute=model.minuteIndex-1500;
    NSString *minute=[NSString stringWithFormat:@"%ld",(long)clockMinute];
    if (clockMinute<10) {
        minute=[NSString stringWithFormat:@"0%ld",(long)clockMinute];
    }
    NSString *clockTime=nil;
    if (model.timeIndex==0) {
        clockTime=@"上午";
    } else if (model.timeIndex==1){
        clockTime=@"下午";
    }
    NSString *alarmTime=[NSString stringWithFormat:@"%@  %@:%@",clockTime,hour,minute];
    NSString *alarmWeek=@"不重复";
    if (model.weekArr.count>0) {
        alarmWeek=@"星期";
        for (NSString *weekStr in model.weekArr) {
            NSString *str=[weekStr substringFromIndex:2];
            alarmWeek=[alarmWeek stringByAppendingString:[NSString stringWithFormat:@"%@ ",str]];
            NSLog(@"alarmWeek=%@",alarmWeek);
        }
    }
    
    NSDictionary *clockDic=[NSDictionary dictionaryWithObjectsAndKeys:alarmTime,@"TIME",alarmWeek,@"WEEK",nil];
    
    if (!model.changeClock) {
        [model.alarmArr addObject:clockDic];
        [model.alarmWeekArr addObject:model.weekArr];
        [model.alarmWeekIndexArr addObject:model.weekIndexArr];
        if (![userDefaults valueForKey:@"showWel1.0"]) {
            [model.segIndexArr addObject:[NSString stringWithFormat:@"%d",model.morenSeg]];
            [model.sleepMoreOpen addObject:[NSNumber numberWithBool:NO]];
        } else{
            [model.segIndexArr addObject:[NSString stringWithFormat:@"%d",(int)_seg.selectedSegmentIndex]];
            [model.sleepMoreOpen addObject:[NSNumber numberWithBool:self.sleep]];
        }
        
    } else {
        [model.alarmArr removeObjectAtIndex:model.deleteIndex];
        [model.alarmWeekArr removeObjectAtIndex:model.deleteIndex];
        [model.alarmWeekIndexArr removeObjectAtIndex:model.deleteIndex];
        [model.segIndexArr removeObjectAtIndex:model.deleteIndex];
        [model.sleepMoreOpen removeObjectAtIndex:model.deleteIndex];
        [model.sleepMoreOpen insertObject:[NSNumber numberWithBool:self.sleep] atIndex:model.deleteIndex];
        
        [model.segIndexArr insertObject:[NSString stringWithFormat:@"%d",(int)_seg.selectedSegmentIndex] atIndex:model.deleteIndex];
        [model.alarmArr insertObject:clockDic atIndex:model.deleteIndex];
        [model.alarmWeekArr insertObject:model.weekArr atIndex:model.deleteIndex];
        [model.alarmWeekIndexArr insertObject:model.weekIndexArr atIndex:model.deleteIndex];
    }
    model.chaKan=NO;
    model.changeClock=NO;
    
    NSLog(@"alarmArr=%@",model.alarmArr);
    [[NSUserDefaults standardUserDefaults] setObject:model.sleepMoreOpen forKey:@"SLEEPMOREOPEN"];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmArr forKey:@"ALARMARR"];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmWeekArr forKey:@"ALARMWEEK"];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmWeekIndexArr forKey:@"ALARMWEEKINDEX"];
    [[NSUserDefaults standardUserDefaults] setObject:model.segIndexArr forKey:@"SEGARR"];
    
    [self.clockTable reloadData];
    [UIView animateWithDuration:0.3 animations:^{
        [self.view viewWithTag:888].frame=CGRectMake(0, -self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
    }];
    
    NSLog(@"segindexArr!!!=%@",model.segIndexArr);
    [[self.rightBtn viewWithTag:777] removeFromSuperview];
    [self.rightBtn setImage:[UIImage imageNamed:@"home_add@2x.png"] forState:UIControlStateNormal];
    ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"挖兔闹钟";
}

- (void)clockSettings
{
#pragma mark - 闹钟
    
    SXModel *model=[SXModel shareModel];
    
    UIView *clockView=[[UIView alloc] initWithFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
    clockView.backgroundColor=[UIColor whiteColor];
    clockView.tag=888;
    [self.view addSubview:clockView];
    
    self.datePicker=[[UIPickerView alloc] initWithFrame:CGRectMake(0, 10, clockView.frame.size.width, 100)];
    self.datePicker.delegate=self;
    self.datePicker.dataSource=self;
    [self.datePicker selectRow:model.timeIndex inComponent:0 animated:NO];
    [self.datePicker selectRow:model.hourIndex inComponent:1 animated:NO];
    [self.datePicker selectRow:model.minuteIndex inComponent:2 animated:NO];
    [clockView addSubview:self.datePicker];
    
    
    self.clockTableView1=[[UITableView alloc] initWithFrame:CGRectMake(0, self.datePicker.frame.origin.y+CGRectGetHeight(self.datePicker.frame)+12, clockView.frame.size.width, 30*2) style:UITableViewStylePlain];
    self.clockTableView1.dataSource=self;
    self.clockTableView1.delegate=self;
    self.clockTableView1.scrollEnabled=NO;
    self.clockTableView1.separatorStyle=UITableViewCellSeparatorStyleNone;
    [clockView addSubview:self.clockTableView1];
    
    self.clockTableView2=[[UITableView alloc] initWithFrame:CGRectMake(0, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), clockView.frame.size.width, 60) style:UITableViewStylePlain];
    self.clockTableView2.dataSource=self;
    self.clockTableView2.delegate=self;
    self.clockTableView2.scrollEnabled=NO;
    [clockView addSubview:self.clockTableView2];
    
    
    UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(15, self.datePicker.frame.origin.y+CGRectGetHeight(self.datePicker.frame)+5, clockView.frame.size.width, 0.5)];
    view1.backgroundColor=[UIColor lightGrayColor];
    view1.alpha=0.8;
    [clockView addSubview:view1];
    
    UIView *view2=[[UIView alloc] initWithFrame:CGRectMake(15, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), clockView.frame.size.width, 0.5)];
    view2.backgroundColor=[UIColor lightGrayColor];
    view2.alpha=0.8;
    [clockView addSubview:view2];
    
//    self.clockSettingTable=[[UITableView alloc] initWithFrame:CGRectMake(0, self.clockTableView2.frame.origin.y, self.clockTableView1.frame.size.width, 0) style:UITableViewStylePlain];
//    self.clockSettingTable.dataSource=self;
//    self.clockSettingTable.delegate=self;
//    self.clockSettingTable.scrollEnabled=NO;
//    [clockView addSubview:self.clockSettingTable];
    
    UIButton *confirmBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    confirmBtn.frame=CGRectMake(50, self.clockTableView2.frame.origin.y+CGRectGetHeight(self.clockTableView2.frame)+60, self.clockTableView1.frame.size.width-100, 40);
    if (!model.chaKan) {
        [confirmBtn setTitle:@"确认闹钟" forState:UIControlStateNormal];
        [confirmBtn addTarget:self action:@selector(calculateClock) forControlEvents:UIControlEventTouchUpInside];
    } else {
        [confirmBtn setTitle:@"保存修改" forState:UIControlStateNormal];
        [confirmBtn addTarget:self action:@selector(changeClock) forControlEvents:UIControlEventTouchUpInside];
    }
    
    confirmBtn.backgroundColor=[self colorWithHexString:@"#9E59E4"];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //confirmBtn.alpha=0.5;
    confirmBtn.tag=901;
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [clockView addSubview:confirmBtn];
    
    UIButton *cancelBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    cancelBtn.frame=CGRectMake(50, confirmBtn.frame.origin.y+CGRectGetHeight(confirmBtn.frame)+10, self.clockTableView1.frame.size.width-100, 40);
    if (!model.chaKan) {
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(cancelClock) forControlEvents:UIControlEventTouchUpInside];
    } else {
        [cancelBtn setTitle:@"删除闹钟" forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(deleteClock) forControlEvents:UIControlEventTouchUpInside];
    }
    
    cancelBtn.backgroundColor=[self colorWithHexString:@"#9E59E4"];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //cancelBtn.alpha=0.5;
    cancelBtn.tag=902;
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [clockView addSubview:cancelBtn];
    
    
    
//    if (model.alarmArr.count==0) {
//        [NSThread sleepForTimeInterval:0.1];
//        [UIView animateWithDuration:0.8 animations:^{
//            clockView.frame=self.view.bounds;
//        }];
//    }
    
}

- (void)changeClock
{
    SXModel *model=[SXModel shareModel];
    model.changeClock=YES;
//    NSLog(@"schel=%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
//    [[UIApplication sharedApplication] cancelLocalNotification:[[[UIApplication sharedApplication] scheduledLocalNotifications] objectAtIndex:model.deleteIndex]];
    NSMutableArray *arr=[model.localNotiArr objectAtIndex:model.deleteIndex];
    for (NSDictionary *dic in arr) {
        NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
        UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
    }
    
    [model.localNotiArr removeObjectAtIndex:model.deleteIndex];
    
    NSLog(@"systemLocalNoti=%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
    NSLog(@"model.localNoti=%@",model.localNotiArr);
    
    [self calculateClock];

}

- (void)deleteClock
{
    SXModel *model=[SXModel shareModel];
    model.chaKan=NO;
    model.changeClock=NO;
    //NSLog(@"%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
//    [[UIApplication sharedApplication] cancelLocalNotification:[[[UIApplication sharedApplication] scheduledLocalNotifications] objectAtIndex:model.deleteIndex]];
    
    
    
    NSMutableArray *arr=[model.localNotiArr objectAtIndex:model.deleteIndex];
    for (NSDictionary *dic in arr) {
        NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
        UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
    }
    
    [model.alarmArr removeObjectAtIndex:model.deleteIndex];
    [model.alarmWeekArr removeObjectAtIndex:model.deleteIndex];
    [model.alarmWeekIndexArr removeObjectAtIndex:model.deleteIndex];
    [model.localNotiArr removeObjectAtIndex:model.deleteIndex];
    [model.segIndexArr removeObjectAtIndex:model.deleteIndex];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmArr forKey:@"ALARMARR"];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmWeekArr forKey:@"ALARMWEEK"];
    [[NSUserDefaults standardUserDefaults] setObject:model.alarmWeekIndexArr forKey:@"ALARMWEEKINDEX"];
    [[NSUserDefaults standardUserDefaults] setObject:model.localNotiArr forKey:@"NOTIARR"];
    [[NSUserDefaults standardUserDefaults] setObject:model.segIndexArr forKey:@"SEGARR"];
    
    
    //NSLog(@"model.localNoti=%@",model.localNotiArr);
    NSLog(@"systemLocalNoti=%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
    
    [self.clockTable reloadData];
    
    [UIView animateWithDuration:0.3 animations:^{
        [self.view viewWithTag:888].frame=CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    }];
    
    [[self.rightBtn viewWithTag:777] removeFromSuperview];
    [self.rightBtn setImage:[UIImage imageNamed:@"home_add@2x.png"] forState:UIControlStateNormal];
    ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"挖兔闹钟";
}

- (void)cancelClock
{
    [UIView animateWithDuration:0.3 animations:^{
        [self.view viewWithTag:888].frame=CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    }];
    [[self.rightBtn viewWithTag:777] removeFromSuperview];
    [self.rightBtn setImage:[UIImage imageNamed:@"home_add@2x.png"] forState:UIControlStateNormal];
    ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"挖兔闹钟";
    
    SXModel *model=[SXModel shareModel];
    model.clockSetOpen=NO;
}

- (void)clockPlayer
{
    //从budle路径下读取音频文件　　轻音乐 - 萨克斯回家 这个文件名是你的歌曲名字,mp3是你的音频格式
    NSString *string = [[NSBundle mainBundle] pathForResource:@"summer" ofType:@"mp3"];
    //把音频文件转换成url格式
    NSURL *url = [NSURL fileURLWithPath:string];
    //初始化音频类 并且添加播放文件
    _avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    //设置代理
    _avAudioPlayer.delegate = self;
    
    //设置初始音量大小
    _avAudioPlayer.volume = 5;
    
    //设置音乐播放次数  -1为一直循环
    _avAudioPlayer.numberOfLoops = -1;
    
    //预播放
    [_avAudioPlayer prepareToPlay];
    
    [self clockPlay];
    //声音开关控件(静音)
//    UISwitch *swith = [[UISwitch alloc] initWithFrame:CGRectMake(100, 20, 60, 40)];
//    [swith addTarget:self action:@selector(onOrOff:) forControlEvents:UIControlEventValueChanged];
//    //默认状态为打开
//    swith.on = YES;
//    [self.view addSubview:swith];
    
}

//播放
- (void)clockPlay
{
    [_avAudioPlayer play];
}
//暂停
- (void)pause
{
    [_avAudioPlayer pause];
}
//停止
- (void)clockStop
{
    for (int i=800; i<804; i++) {
        [self.view viewWithTag:i].frame=CGRectMake(80*(i-800), self.view.frame.size.height, 80, 80);
    }
    
    _avAudioPlayer.currentTime = 0;  //当前播放时间设置为0
    [_avAudioPlayer stop];
    SXModel *model=[SXModel shareModel];
    model.timeIndex=0;
    model.hourIndex=605;
    model.minuteIndex=1500;
    model.clockSelectOpen=0;
    model.refreshData=NO;
    self.refreshed=0;
    self.rightBtn.hidden=NO;
    self.refreshNum=0;
    
    self.clockTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.clockTable.delegate=self;
    self.clockTable.dataSource=self;
    [self setExtraCellLineHidden:self.clockTable];
    [self.view addSubview:self.clockTable];
}

//播放完成时调用的方法  (代理里的方法),需要设置代理才可以调用
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
    
}

//判断刷新
- (void)isRefreshData
{
    SXModel *model=[SXModel shareModel];
    if (!model.refreshData) {
        model.clockSelectOpen=0;
        self.refreshed=0;
        self.refreshNum=0;
        isNewSearch=YES;
        [self fetchSettingInfo];
    }
}

- (void)createSelectBtn:(NSMutableArray *)putArr iconArr:(NSMutableArray *)iconArr
{
    SXModel *model=[SXModel shareModel];
    float height=80;
    if (!model.startSelect) {
        for (int i=0; i<4; i++) {
            switch (i) {
                case 0:{
                    _button1=[[UIButton alloc] initWithFrame:CGRectMake(height*i,self.view.frame.size.height, height, height)];
                    _button1.backgroundColor=[UIColor clearColor];
                    _button1.alpha=1;
                    
                    UIView *view=[[UIView alloc] initWithFrame:_button1.bounds];
                    UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:0]]];
                    //UIImage *image=[UIImage imageNamed:@"hat@2x.png"];
                    
                    UIImageView *imageView=[[UIImageView alloc] initWithImage:image];
                    imageView.frame=CGRectMake(view.frame.size.width/2-image.size.width/2, 0, image.size.width, image.size.height);
                    imageView.userInteractionEnabled=YES;
                    imageView.tag=677;
                    [view addSubview:imageView];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.size.height+2, view.frame.size.width, view.frame.size.height-(imageView.frame.size.height+2))];
                    label.text=[putArr objectAtIndex:0];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.font=[UIFont boldSystemFontOfSize:11];
                    label.textColor=[self colorWithHexString:@"#9E59E4"];
                    label.tag=676;
                    [view addSubview:label];
                    view.tag=767;
                    view.userInteractionEnabled=YES;
                    
                    view.backgroundColor=[UIColor whiteColor];
                    view.alpha=0.8;
                    [_button1 addSubview:view];
                    UIButton *btn=[[UIButton alloc] initWithFrame:_button1.bounds];
                    btn.backgroundColor=[UIColor clearColor];
                    [btn addTarget:self action:@selector(clockBtn1:) forControlEvents:UIControlEventTouchUpInside];
                    btn.tag=5000;
                    [_button1 addSubview:btn];
                    
                    _button1.tag=800+i;
                    [self.view addSubview:_button1];
                }
                    break;
                case 1:{
                    _button2=[[UIButton alloc] initWithFrame:CGRectMake(height*i,self.view.frame.size.height, height, 80)];
                    _button2.backgroundColor=[UIColor clearColor];
                    _button2.alpha=1;
                    
                    UIView *view=[[UIView alloc] initWithFrame:_button2.bounds];
                    UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:1]]];
                    //UIImage *image=[UIImage imageNamed:@"hat@2x.png"];
                    UIImageView *imageView=[[UIImageView alloc] initWithImage:image];
                    imageView.frame=CGRectMake(view.frame.size.width/2-image.size.width/2, 0, image.size.width, image.size.height);
                    imageView.userInteractionEnabled=YES;
                    imageView.tag=677;
                    [view addSubview:imageView];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.size.height+2, view.frame.size.width, view.frame.size.height-(imageView.frame.size.height+2))];
                    label.text=[putArr objectAtIndex:1];
                    label.font=[UIFont boldSystemFontOfSize:11];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.textColor=[self colorWithHexString:@"#9E59E4"];
                    label.tag=676;
                    [view addSubview:label];
                    view.tag=767;
                    view.userInteractionEnabled=YES;
                    view.backgroundColor=[UIColor whiteColor];
                    view.alpha=0.8;
                    [_button2 addSubview:view];
                    
                    UIButton *btn=[[UIButton alloc] initWithFrame:_button2.bounds];
                    btn.backgroundColor=[UIColor clearColor];
                    [btn addTarget:self action:@selector(clockBtn2:) forControlEvents:UIControlEventTouchUpInside];
                    btn.tag=5001;
                    [_button2 addSubview:btn];
                    
                    _button2.tag=800+i;
                    [self.view addSubview:_button2];
                }
                    break;
                case 2:{
                    _button3=[[UIButton alloc] initWithFrame:CGRectMake(height*i,self.view.frame.size.height, height, 80)];
                    _button3.backgroundColor=[UIColor clearColor];
                    _button3.alpha=1;
                    
                    UIView *view=[[UIView alloc] initWithFrame:_button3.bounds];
                    UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:2]]];
                    //UIImage *image=[UIImage imageNamed:@"hat@2x.png"];
                    UIImageView *imageView=[[UIImageView alloc] initWithImage:image];
                    imageView.frame=CGRectMake(view.frame.size.width/2-image.size.width/2, 0, image.size.width, image.size.height);
                    imageView.userInteractionEnabled=YES;
                    imageView.tag=677;
                    [view addSubview:imageView];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.size.height+2, view.frame.size.width, view.frame.size.height-(imageView.frame.size.height+2))];
                    label.text=[putArr objectAtIndex:2];
                    label.font=[UIFont boldSystemFontOfSize:11];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.textColor=[self colorWithHexString:@"#9E59E4"];
                    label.tag=676;
                    [view addSubview:label];
                    view.tag=767;
                    view.userInteractionEnabled=YES;
                    view.backgroundColor=[UIColor whiteColor];
                    view.alpha=0.8;
                    [_button3 addSubview:view];
                    
                    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                    btn.backgroundColor=[UIColor clearColor];
                    btn.frame=_button3.bounds;
                    [btn addTarget:self action:@selector(clockBtn3:) forControlEvents:UIControlEventTouchUpInside];
                    btn.tag=5002;
                    [_button3 addSubview:btn];
                    
                    _button3.tag=800+i;
                    [self.view addSubview:_button3];
                }
                    break;
                case 3:{
                    _button4=[[UIButton alloc] initWithFrame:CGRectMake(height*i,self.view.frame.size.height, height, 80)];
                    _button4.backgroundColor=[UIColor clearColor];
                    _button4.alpha=1;
                    
                    UIView *view=[[UIView alloc] initWithFrame:_button4.bounds];
                    UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:3]]];
                    //UIImage *image=[UIImage imageNamed:@"hat@2x.png"];
                    UIImageView *imageView=[[UIImageView alloc] initWithImage:image];
                    imageView.frame=CGRectMake(view.frame.size.width/2-image.size.width/2, 0, image.size.width, image.size.height);
                    imageView.userInteractionEnabled=YES;
                    imageView.tag=677;
                    [view addSubview:imageView];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, imageView.frame.size.height+2, view.frame.size.width, view.frame.size.height-(imageView.frame.size.height+2))];
                    label.text=[putArr objectAtIndex:3];
                    label.font=[UIFont boldSystemFontOfSize:11];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.textColor=[self colorWithHexString:@"#9E59E4"];
                    label.tag=676;
                    [view addSubview:label];
                    view.tag=767;
                    view.userInteractionEnabled=YES;
                    view.backgroundColor=[UIColor whiteColor];
                    view.alpha=0.8;
                    [_button4 addSubview:view];
                    
                    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                    btn.backgroundColor=[UIColor clearColor];
                    btn.frame=_button4.bounds;
                    [btn addTarget:self action:@selector(clockBtn4:) forControlEvents:UIControlEventTouchUpInside];
                    btn.tag=5003;
                    [_button4 addSubview:btn];
                    
                    _button4.tag=800+i;
                    [self.view addSubview:_button4];
                    
                }
                    break;
                default:
                    break;
            }
            
        }
        
        model.startSelect=YES;
        
    } else {
        _button1.frame=CGRectMake(0,self.view.frame.size.height, height, 80);
        _button2.frame=CGRectMake(80,self.view.frame.size.height, height, 80);
        _button3.frame=CGRectMake(80*2,self.view.frame.size.height, height, 80);
        _button4.frame=CGRectMake(80*3,self.view.frame.size.height, height, 80);
        
        ((UILabel *)[[_button1 viewWithTag:767] viewWithTag:676]).text=[putArr objectAtIndex:0];
        ((UILabel *)[[_button2 viewWithTag:767] viewWithTag:676]).text=[putArr objectAtIndex:1];
        ((UILabel *)[[_button3 viewWithTag:767] viewWithTag:676]).text=[putArr objectAtIndex:2];
        ((UILabel *)[[_button4 viewWithTag:767] viewWithTag:676]).text=[putArr objectAtIndex:3];
        
        ((UIImageView *)[[_button1 viewWithTag:767] viewWithTag:677]).image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:0]]];
        ((UIImageView *)[[_button2 viewWithTag:767] viewWithTag:677]).image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:1]]];
        ((UIImageView *)[[_button3 viewWithTag:767] viewWithTag:677]).image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:2]]];
        ((UIImageView *)[[_button4 viewWithTag:767] viewWithTag:677]).image=[UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png",[iconArr objectAtIndex:3]]];
        
    }
    
    [UIView animateWithDuration:0.5 animations:^{
        for (int i=800; i<804; i++) {
            [self.view viewWithTag:i].frame=CGRectMake(height*(i-800), self.view.frame.size.height-height, height, height);
        }
        
    } completion:^(BOOL finished) {
        
            switch (self.refreshed) {
                case 0:{
                    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-150, self.view.frame.size.height/2, 300, 30)];
                    view.backgroundColor=[UIColor grayColor];
                    view.alpha=0;
                    [self.view addSubview:view];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:view.bounds];
                    label.textColor=[UIColor whiteColor];
                    label.font=[UIFont boldSystemFontOfSize:14];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.text=@"选出下列图片中哪类衣服颜色相同";
                    label.alpha=0;
                    [view addSubview:label];
                    
                    [UIView animateWithDuration:1.0 animations:^{
                        view.alpha=1;
                        label.alpha=1;
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:3.0 animations:^{
                            view.alpha=0;
                        } completion:^(BOOL finished) {
                            [view removeFromSuperview];
                            self.refreshed++;
                            [self performSelector:@selector(isRefreshData) withObject:nil afterDelay:0.3];
                        }];
                    }];
                }
                    break;
                case 1:{
                    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height/2, 100, 30)];
                    view.backgroundColor=[UIColor grayColor];
                    view.alpha=0;
                    [self.view addSubview:view];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:view.bounds];
                    label.textColor=[UIColor whiteColor];
                    label.font=[UIFont boldSystemFontOfSize:14];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.text=@"再选一次";
                    label.alpha=0;
                    [view addSubview:label];
                    
                    [UIView animateWithDuration:1.0 animations:^{
                        view.alpha=1;
                        label.alpha=1;
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:3.0 animations:^{
                            view.alpha=0;
                        } completion:^(BOOL finished) {
                            [view removeFromSuperview];
                            self.refreshed++;
                        }];
                    }];
                }
                    break;
                case 2:{
                    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height/2, 100, 30)];
                    view.backgroundColor=[UIColor grayColor];
                    view.alpha=0;
                    [self.view addSubview:view];
                    
                    UILabel *label=[[UILabel alloc] initWithFrame:view.bounds];
                    label.textColor=[UIColor whiteColor];
                    label.font=[UIFont boldSystemFontOfSize:14];
                    label.textAlignment=NSTextAlignmentCenter;
                    label.text=@"最后一次";
                    label.alpha=0;
                    [view addSubview:label];
                    
                    [UIView animateWithDuration:1.0 animations:^{
                        view.alpha=1;
                        label.alpha=1;
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:3.0 animations:^{
                            view.alpha=0;
                        } completion:^(BOOL finished) {
                            [view removeFromSuperview];
                            self.refreshed=0;
                        }];
                    }];
                }
                    break;
                default:
                    break;
            }
        
    }];
}

- (void)clockBtn1:(UIButton *)button
{
    SXModel *model=[SXModel shareModel];
    
    if ([((UILabel *)[[[button superview] viewWithTag:767] viewWithTag:676]).text isEqualToString:model.correctSelect]) {
        if (model.clockSelectOpen<3) {
            [self refreshView];
        } else {
            [[self.view viewWithTag:888] removeFromSuperview];
            [self.clockTable removeFromSuperview];
            //self.collectionView.alpha=0;
            [self clockSettings];
            [self clockStop];
        }
        
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错了哟"
                                                        message:nil
                                                       delegate:self
                                              cancelButtonTitle:@"再来"
                                              otherButtonTitles:nil];
        [alert show];
    }
    
}
- (void)clockBtn2:(UIButton *)button
{
    SXModel *model=[SXModel shareModel];
    if ([((UILabel *)[[[button superview] viewWithTag:767] viewWithTag:676]).text isEqualToString:model.correctSelect]) {
        if (model.clockSelectOpen<3) {
            [self refreshView];
        } else {
            [[self.view viewWithTag:888] removeFromSuperview];
            [self.clockTable removeFromSuperview];
            [self clockSettings];
            [self clockStop];
        }
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错了哟"
                                                        message:nil
                                                       delegate:self
                                              cancelButtonTitle:@"再来"
                                              otherButtonTitles:nil];
        [alert show];
    }
}
- (void)clockBtn3:(UIButton *)button
{
    SXModel *model=[SXModel shareModel];
    if ([((UILabel *)[[[button superview] viewWithTag:767] viewWithTag:676]).text isEqualToString:model.correctSelect]) {
        if (model.clockSelectOpen<3) {
            [self refreshView];
        } else {
            [[self.view viewWithTag:888] removeFromSuperview];
            [self.clockTable removeFromSuperview];
            [self clockSettings];
            [self clockStop];
        }
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错了哟"
                                                        message:nil
                                                       delegate:self
                                              cancelButtonTitle:@"再来"
                                              otherButtonTitles:nil];
        [alert show];
    }
}
- (void)clockBtn4:(UIButton *)button
{
    SXModel *model=[SXModel shareModel];
    if ([((UILabel *)[[[button superview] viewWithTag:767] viewWithTag:676]).text isEqualToString:model.correctSelect]) {
        if (model.clockSelectOpen<3) {
            [self refreshView];
        } else {
            [[self.view viewWithTag:888] removeFromSuperview];
            [self.clockTable removeFromSuperview];
            [self clockSettings];
            [self clockStop];
        }
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错了哟"
                                                        message:nil
                                                       delegate:self
                                              cancelButtonTitle:@"再来"
                                              otherButtonTitles:nil];
        [alert show];
    }
}

- (void)sleepForAwhile
{
    UILocalNotification *noti = [[UILocalNotification alloc] init];
    
    NSDate *date=[NSDate new];
    
    if (noti) {
        
        //设置推送时间
        
        noti.fireDate = [date dateByAddingTimeInterval:5*60];
        
        //设置时区
        
        noti.timeZone = [NSTimeZone defaultTimeZone];
        
        //设置重复间隔
        
        noti.repeatInterval = kCFCalendarUnitWeek;
        
        //推送声音
        
        //noti.soundName = UILocalNotificationDefaultSoundName;
        //noti.soundName=[[NSBundle mainBundle] pathForResource:@"summer" ofType:@"caf"];
        noti.soundName=@"summer.mp3";
        
        //右上角消息个数
        noti.applicationIconBadgeNumber++;
        
        //内容
        
        noti.alertBody = @"哈喽";
        noti.alertAction= NSLocalizedString(@"起床了", nil);
        
        //显示在icon上的红色圈中的数子
        
        noti.applicationIconBadgeNumber = 1;
        
        //设置userinfo 方便在之后需要撤销的时候使用
        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"SLEEPMORE" forKey:@"key"];
        
        noti.userInfo = infoDic;
        
        //添加推送到uiapplication
        UIApplication *app = [UIApplication sharedApplication];
        
        [app scheduleLocalNotification:noti];
        
        SXModel *model=[SXModel shareModel];
        model.sleepMore=YES;
        
        [[self.view viewWithTag:797] removeFromSuperview];
        [[self.view viewWithTag:888] removeFromSuperview];
        [self.clockTable removeFromSuperview];
        [self clockSettings];
        [self clockStop];
        
        
    }
}

#pragma mark -
- (void)clockSelectBtn
{
    SXModel *model=[SXModel shareModel];
    if (model.clockSelectOpen<3) {
        //弹出选项框
        NSLog(@"选择的答案是=%@",[self dataFromDBCostume:nil which:NO]);
        model.correctSelect=[self dataFromDBCostume:nil which:NO];
        NSMutableArray *selectArr=[NSMutableArray arrayWithArray:model.selectArr];
        NSLog(@"1sle=%@",selectArr);
        for (NSString *str in selectArr) {
            if ([str isEqualToString:[self dataFromDBCostume:nil which:NO]]) {
                [selectArr removeObject:str];
                break;
            }
        }
        
        NSString *select1=[selectArr objectAtIndex:arc4random()%selectArr.count];
        for (NSString *str in selectArr) {
            if ([str isEqualToString:select1]) {
                [selectArr removeObject:str];
                break;
            }
        }
        NSString *select2=[selectArr objectAtIndex:arc4random()%selectArr.count];
        for (NSString *str in selectArr) {
            if ([str isEqualToString:select2]) {
                [selectArr removeObject:str];
                break;
            }
        }
        NSString *select3=[selectArr objectAtIndex:arc4random()%selectArr.count];
        NSLog(@"sle1=%@,%@,%@",select1,select2,select3);
        //产生随机位置
        NSMutableArray *indexSelect=[[NSMutableArray alloc] init];
        NSMutableArray *selectPut=[[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2",@"3",nil];
        int indexR=arc4random()%4;
        int index1=indexR;
        while (index1==indexR) {
            index1=arc4random()%4;
        }
        int index2=index1;
        while (index2==indexR || index2==index1) {
            index2=arc4random()%4;
        }
        int index3=index2;
        while (index3==indexR || index3==index1 || index3==index2) {
            index3=arc4random()%4;
        }
        [indexSelect addObject:[NSNumber numberWithInt:indexR]];
        [indexSelect addObject:[NSNumber numberWithInt:index1]];
        [indexSelect addObject:[NSNumber numberWithInt:index2]];
        [indexSelect addObject:[NSNumber numberWithInt:index3]];
        
        for (int j=0; j<indexSelect.count; j++) {
            NSString *str=[indexSelect objectAtIndex:j];
            NSLog(@"str=%@",str);
            for (int i=0; i<selectPut.count; i++) {
                if ([str intValue]==i) {
                    switch (j) {
                        case 0:{
                            [selectPut removeObjectAtIndex:i];
                            [selectPut insertObject:[self dataFromDBCostume:nil which:NO] atIndex:i];
                        }
                            break;
                        case 1:{
                            [selectPut removeObjectAtIndex:i];
                            [selectPut insertObject:select1 atIndex:i];
                        }
                            break;
                        case 2:{
                            [selectPut removeObjectAtIndex:i];
                            [selectPut insertObject:select2 atIndex:i];
                            
                        }
                            break;
                        case 3:{
                            [selectPut removeObjectAtIndex:i];
                            [selectPut insertObject:select3 atIndex:i];
                            
                        }
                            break;
                        default:
                            break;
                    }
                    
                }
            }
        }
        
        if (selectPut.count==4) {
            NSMutableArray *iconArr=[[NSMutableArray alloc] init];
            for (NSString *name in selectPut) {
                NSLog(@"name=%@",name);
                NSString *iconStr=[self dataFromDBCostume:[NSString stringWithFormat:@"'%@'",name] which:YES];
                [iconArr addObject:iconStr];
            }
            NSLog(@"selectPut=%@",selectPut);
            NSLog(@"iconArr=%@",iconArr);
            model.clockSelectOpen++;
            [self createSelectBtn:selectPut iconArr:iconArr];
            //model.clockSelectOpen=YES;
        }
    }
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    //[self notificationClock];
    
    self.refreshed=0;
    self.iPhone=NO;
    self.notiArr=NO;
    
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    //CGFloat width = size.width;
    CGFloat height = size.height;
    if (height<500) {
        self.iPhone=YES;
    }
    
    
    //后台播放音频设置
//    AVAudioSession *session = [AVAudioSession sharedInstance];
//    [session setActive:YES error:nil];
//    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    //self.automaticallyAdjustsScrollViewInsets = NO;
    
    SearchDic = [[NSMutableDictionary alloc] init];
    self.kuanshiDataArr=[[NSMutableArray alloc] init];
    self.kuanshi2FrameArr=[[NSMutableArray alloc] init];
    self.kuanshi1OutTimes=6;
    filterViewType = EM_FVT_NONE;
    topOneType = EM_TOT_NONE;
    colorIndex = 0;
    viewType = EM_VT_Home;
    self.leftBtn.hidden = YES;
    isLeftBtnHistory = YES;
    isNewSearch = YES;
    isFetchData = NO;
    cumtomerID = nil;
    colorID = nil;
    self.changed=NO;
    self.defaultImgArr=[[NSMutableArray alloc] init];
    self.indexArr=[[NSArray alloc] initWithObjects:@"16",@"1",@"2", nil];
    self.weekArr=[NSMutableArray arrayWithObjects:@"小睡一下",@"铃声设置",nil];
    self.weekSArr=[[NSMutableArray alloc] initWithObjects:@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",@"星期日", nil];
    
    userDefaults = [NSUserDefaults standardUserDefaults];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(becomeSelect) name:@"SELECT" object:nil];
    //
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.internetReachability = [Reachability reachabilityForInternetConnection];
    [self.internetReachability startNotifier];
    [self updateInterfaceWithReachability:self.internetReachability];
    
    self.wifiReachability = [Reachability reachabilityForLocalWiFi];
    [self.wifiReachability startNotifier];
    [self updateInterfaceWithReachability:self.wifiReachability];
    
    
    //[self.leftBtn setImage:[UIImage imageNamed:@"home_history_icon.png"] forState:UIControlStateNormal];
    self.leftBtn.hidden=YES;
    self.leftBtn.userInteractionEnabled=YES;
    
    //
    self.rightBtn=[[UIButton alloc] initWithFrame:CGRectMake([self screenSize].width-90, -2, 100, 50)];
    //self.rightBtn.backgroundColor=[UIColor redColor];
    [self.rightBtn setImage:[UIImage imageNamed:@"home_add@2x.png"] forState:UIControlStateNormal];
    [self.rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightBtn setContentMode:UIViewContentModeRight];
    [self.navigationController.navigationBar addSubview:self.rightBtn];
        
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.navigationController.navigationBar.frame.size.width/2-50, 0, 100, self.navigationController.navigationBar.frame.size.height)];
    titleLabel.backgroundColor=[UIColor whiteColor];
    titleLabel.text=@"挖兔闹钟";
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[self colorWithHexString:@"#9E59E4"];
    titleLabel.font=[UIFont boldSystemFontOfSize:23];
    titleLabel.tag=1000;
    [self.navigationController.navigationBar addSubview:titleLabel];
    
    
    HomeViewFlowLayout *cvLayout = [[HomeViewFlowLayout alloc] init];
    //model.infoArr = [[NSMutableArray alloc] init];
    cvLayout.delegate = self;
    cvLayout.itemWidth = 150.0f;
    cvLayout.topInset = 6.0f;
    cvLayout.bottomInset = 6.0f;
    cvLayout.stickyHeader = NO;
    //isDefaultFetch = YES;
    isAddSearch = NO;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:cvLayout];
    [self.collectionView registerClass:[ContentCollectionViewCell class] forCellWithReuseIdentifier:kCellID];
    [self.collectionView registerClass:[HomeWaterfallHeaderReusableView class] forSupplementaryViewOfKind:@"UICollectionElementKindSectionHeader" withReuseIdentifier:WaterfallHeaderIdentifier];
    self.collectionView.backgroundColor = [UIColor colorWithRed:226.f/255.f green:226.f/255 blue:226.f/255.f alpha:1.f];
    self.collectionView.delegate = self;
    [self.collectionView setCollectionViewLayout:cvLayout];
    self.collectionView.showsVerticalScrollIndicator=NO;
    self.collectionView.alpha=1;
    [self.collectionView reloadData];
    
    self.clockTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.clockTable.delegate=self;
    self.clockTable.dataSource=self;
    [self setExtraCellLineHidden:self.clockTable];
    [self.view addSubview:self.clockTable];
    
    if (![userDefaults valueForKey:@"showWel1.0"]) {
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
    }
    
    SXModel *model=[SXModel shareModel];
    if (!model.noti) {
        [self clockSettings];
    } else {
        [self.clockTable removeFromSuperview];
        self.rightBtn.hidden=YES;
        [self clockPlayer];
        [self clockPlay];
    }
    
    isHomeSearch = YES;
    //[self footnetwork];
    
    m_filtertype = EM_FT_None;
    m_filterSubmenutype = EM_FST_NONE;
    [self initDataFromDB];
    [self dataFromWenziDB];
    
    NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"LoadingView" owner:self options:nil];
    lv = [nib objectAtIndex:0];
    [self.view addSubview:lv];
    [lv startAnimation];
    lv.hidden = YES;
    
    //添加下拉刷新
    //    __weak HomeViewController *blockSelf = self;
    //    [self.collectionView addPullToRefreshWithActionHandler:^{
    //        NSLog(@"下拉更新");
    //        //使用GCD开启一个线程，使圈圈转2秒
    //        int64_t delayInSeconds = 1.0;
    //        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    //        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    //            [blockSelf refreshView];
    //            [blockSelf.collectionView.pullToRefreshView stopAnimating];
    //        });
    //    }];
    
    
    if (![userDefaults valueForKey:@"showWel1.0"]) {
        //[userDefaults setObject:@"YES" forKey:@"showWel1.0"];
        //        StartAnimationViewController *startAniVC = [[StartAnimationViewController alloc] initWithNibName:@"StartAnimationViewController" bundle:nil];
        //        [self presentViewController:startAniVC animated:NO completion:^{
        //
        //        }];
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
        
        model.timeIndex=0;
        model.hourIndex=600+6;
        model.minuteIndex=1500;
        _seg=[[UISegmentedControl alloc] init];
        _seg.selectedSegmentIndex=2;
        [model.weekArr addObject:@"星期一"];
        [model.weekArr addObject:@"星期二"];
        [model.weekArr addObject:@"星期三"];
        [model.weekArr addObject:@"星期四"];
        [model.weekArr addObject:@"星期五"];
        [model.weekIndexArr addObject:@"0"];
        [model.weekIndexArr addObject:@"1"];
        [model.weekIndexArr addObject:@"2"];
        [model.weekIndexArr addObject:@"3"];
        [model.weekIndexArr addObject:@"4"];
        [self calculateClock];
        [userDefaults setObject:@"YES" forKey:@"showWel1.0"];
        [self.clockTable reloadData];
    }
    
    if (model.noti) {
        isNewSearch=YES;
        //[self clockSelectBtn];
        [self performSelectorInBackground:@selector(fetchSettingInfo) withObject:nil];
        model.noti=NO;
        
        
        
        //如果小睡，撤销它
        if (model.sleepMore) {
            for (UILocalNotification *not in [[UIApplication sharedApplication] scheduledLocalNotifications]){
                if ([[not valueForKey:@"key"] isEqualToString:@"SLEEPMORE"]) {
                    [[UIApplication sharedApplication] cancelLocalNotification:not];
                    break;
                }
            }
            
            model.sleepMore=NO;
            
        }
        
        
        //如果打开过小睡功能
        NSArray *notiArr=[[UIApplication sharedApplication] scheduledLocalNotifications];
        BOOL same=NO;
        for (UILocalNotification *noti in notiArr) {
            for (int i=0; i<model.localNotiArr.count; i++) {
                NSMutableArray *arr=[model.localNotiArr objectAtIndex:i];
                for (NSDictionary *dic in arr) {
                    NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
                    UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
                    if ([noti isEqual:localNotif]) {
                        self.sleep=[[model.sleepMoreOpen objectAtIndex:i] boolValue];
                        same=YES;
                        break;
                    }
                }
                
                if (same) {
                    break;
                }
            }
            
            if (same) {
                break;
            }
        }
        if (self.sleep) {
            UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height/2, 50, 30)];
            view.backgroundColor=[UIColor whiteColor];
            view.alpha=0.8;
            view.tag=797;
            
            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
            button.frame=view.bounds;
            [button setTitle:@"小睡一下" forState:UIControlStateNormal];
            [button setTitleColor:[self colorWithHexString:@"#9E59E4"] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont boldSystemFontOfSize:14];
            button.titleLabel.textAlignment=NSTextAlignmentCenter;
            [button addTarget:self action:@selector(sleepForAwhile) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
            [self.view addSubview:view];
            
        }
        
    }
    //[NSThread detachNewThreadSelector:@selector(fetchSettingInfo) toTarget:self withObject:nil];
    
}

- (void)becomeSelect
{
    SXModel *model=[SXModel shareModel];
    if (!model.noti) {
        [self clockSettings];
    } else {
        [self.clockTable removeFromSuperview];
        self.collectionView.alpha=1;
        [UIView animateWithDuration:0.8 animations:^{
            [self.view viewWithTag:888].frame=CGRectMake(0, -self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
        } completion:^(BOOL finished) {
            [[self.view viewWithTag:888] removeFromSuperview];
        }];
        self.rightBtn.hidden=YES;
        
        //如果小睡，撤销它
        if (model.sleepMore) {
            for (UILocalNotification *not in [[UIApplication sharedApplication] scheduledLocalNotifications]){
                if ([[not.userInfo valueForKey:@"key"] isEqualToString:@"SLEEPMORE"]) {
                    [[UIApplication sharedApplication] cancelLocalNotification:not];
                    break;
                }
            }
            
            model.sleepMore=NO;
            
        }
        
        //如果打开过小睡功能
        
        BOOL same=NO;
        for (int i=0; i<model.localNotiArr.count; i++) {
            NSMutableArray *arr=[model.localNotiArr objectAtIndex:i];
            for (NSDictionary *dic in arr) {
                NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
                UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
                if ([model.notificaiton isEqual:localNotif]) {
                    self.sleep=[[model.sleepMoreOpen objectAtIndex:i] boolValue];
                    same=YES;
                    break;
                }
            }
            
            if (same) {
                break;
            }
        }
        
        if (self.sleep) {
            UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height/2, 80, 40)];
            view.backgroundColor=[UIColor whiteColor];
            view.alpha=0.8;
            view.tag=797;
            
            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
            button.frame=view.bounds;
            [button setTitle:@"小睡一下" forState:UIControlStateNormal];
            [button setTitleColor:[self colorWithHexString:@"#9E59E4"] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont boldSystemFontOfSize:16];
            button.titleLabel.textAlignment=NSTextAlignmentCenter;
            [button addTarget:self action:@selector(sleepForAwhile) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
            [self.view addSubview:view];
            
        } else
            [[self.view viewWithTag:797] removeFromSuperview];
        
        //[self clockSelectBtn];
        [self clockPlayer];
        [self clockPlay];
        
        //model.colorArr=[NSMutableArray arrayWithArray:[userDefaults valueForKey:@"HomeColors"]];
        isNewSearch=YES;
        [self fetchSettingInfo];
        model.noti=NO;
    
    }
    
    isHomeSearch = YES;
    //[self footnetwork];
    
    m_filtertype = EM_FT_None;
    m_filterSubmenutype = EM_FST_NONE;
    [self initDataFromDB];
    [self dataFromWenziDB];
    
    NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"LoadingView" owner:self options:nil];
    lv = [nib objectAtIndex:0];
    [self.view addSubview:lv];
    [lv startAnimation];
    lv.hidden = YES;
    
}

- (void)refreshView
{
    
    SXModel *model=[SXModel shareModel];
//    if ([[userDefaults valueForKey:@"HomeColors"] count]==0) {
//        model.colorArr=[userDefaults valueForKey:@"HomeColors"];
//    }
    isHomeSearch=YES;
    isNewSearch=YES;
    model.refresh=YES;
    
    NSLog(@"modelColorArr=%@",model.colorArr);
    model.customIndex=arc4random()%([model.colorArr count]);
    
    NSDictionary *dic=[model.colorArr objectAtIndex:model.customIndex];
    NSLog(@"refreshDic=%@",dic);
    cumtomerID=[dic valueForKey:@"CostumeID"];
    NSMutableArray *codesArr=[dic valueForKey:@"Codes"];
    model.colorIndex=arc4random()%[codesArr count];
    
    colorID=[[codesArr objectAtIndex:model.colorIndex] valueForKey:@"Code"];
    NSLog(@"_______________________________________________costumId%@,codeID%@",cumtomerID,colorID);
    
    
    
//    if (model.colorIndex==codesArr.count) {
//        model.colorIndex=0;
//        if (model.customIndex==model.colorArr.count) {
//            model.customIndex=0;
//        } else
//            model.customIndex++;
//    } else
//        model.colorIndex++;
    
    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                             "<soap12:Envelope "
                             "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                             "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                             "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                             "<soap12:Body>"
                             "<HomeShowPicture xmlns=\"http://tempuri.org/\">"
                             "<userid>%@</userid>"
                             "<userip>%@</userip>"
                             "<address>%@</address>"
                             "<date>%@</date>"
                             "<gender>female</gender>"
                             "<firstid>%@</firstid>"
                             "<colorname>%@</colorname>"
                             "<currentpage>%d</currentpage>"
                             "<pagesize>%@</pagesize>"
                             "</HomeShowPicture>"
                             "</soap12:Body>"
                             "</soap12:Envelope>", [[NSUserDefaults standardUserDefaults]valueForKey:@"UserID"],@"",@"",@"",cumtomerID,colorID,1,@"20"];
    CLog(@"%@",soapMessage);
    
    
    
    //请求发送到的路径
    //    NSString *url = [NSString stringWithFormat:@"%@WebService/Watu_WebService.asmx",API_SERVER_URL];
    NSString *soapActionURL = @"http://tempuri.org/HomeShowPicture";
    NetWebServiceRequest *request = [NetWebServiceRequest serviceRequestUrl:API_SERVER_URL SOAPActionURL:soapActionURL ServiceMethodName:@"getMobileCodeInfo" SoapMessage:soapMessage];
    [request startAsynchronous];
    [request setDelegate:self];
    self.runningRequest = request;
    [self clockSelectBtn];
}

- (void)addRefresh
{
    self.collectionView.showsPullToRefresh=YES;
}

- (void)removeRefresh
{
    self.collectionView.showsPullToRefresh=NO;
}

-(void)fetchSettingInfo
{
//    // 要请求的地址
//    NSString *urlString=@"http://www.watoo11.com/WebService/Watu_WebService.asmx?op=GetSettings";
//    // 将地址编码
//    urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
//    // 实例化NSMutableURLRequest，并进行参数配置
//    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//    [request setURL:[NSURL URLWithString: urlString]];
//    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
//    [request setTimeoutInterval: 60];
//    [request setHTTPShouldHandleCookies:FALSE];
//    [request setHTTPMethod:@"GET"];
//    
//    // Response对象，用来得到返回后的数据，比如，用statusCode==200 来判断返回正常
//    NSHTTPURLResponse *response;
//    NSData *returnData = [NSURLConnection sendSynchronousRequest:request
//                                               returningResponse:&response error:nil];
//    
//    // 处理返回的数据
//    if (returnData) {
//        NSString *strReturn = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
//        NSLog(@"%@",strReturn);
//        NSLog(@"%ld",(long)[response statusCode]);
//        
//        //NSData *data = [returnData dataUsingEncoding:NSUTF8StringEncoding];
//        NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];
//        NSString *imgUrl = (NSString *)[jsonObj objectForKey:@"ImageUrl"];
//        NSMutableArray *homeColors = (NSMutableArray *)[jsonObj objectForKey:@"HomeColors"];
//        [userDefaults setObject:imgUrl forKey:@"ImageUrl"];
//        [userDefaults setObject:homeColors forKey:@"HomeColors"];
//    }

    [userDefaults setObject:@"NO" forKey:@"showWel1.0"];
    
    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                             "<soap12:Envelope "
                             "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                             "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                             "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                             "<soap12:Body>"
                             "<%@ xmlns=\"http://tempuri.org/\">"
                             "</%@>"
                             "</soap12:Body>"
                             "</soap12:Envelope>",@"GetSettings",@"GetSettings"];
    
    CLog(@"%@",soapMessage);//[NSString stringWithFormat:@"%d",currentpage+1]
    
    
    //请求发送到的路径
    //    NSString *url = [NSString stringWithFormat:@"%@WebService/Watu_WebService.asmx",API_SERVER_URL];
    NSString *soapActionURL = @"http://tempuri.org/GetSettings";
    NetWebServiceRequest *request = [NetWebServiceRequest serviceRequestUrl:API_SERVER_URL SOAPActionURL:soapActionURL ServiceMethodName:@"getMobileCodeInfo" SoapMessage:soapMessage];
    [request startAsynchronous];
    [request setDelegate:self];
    self.gettingRequest = request;
    NSLog(@"更换请求！！！！——————————————————————");
}

-(NSString *)getImageUrl
{
    NSString *urlStr = [userDefaults objectForKey:@"ImageUrl"];
    if (urlStr && [urlStr length]>0) {
        return urlStr;
    }
//    else
//    {
//        return ImageUrl;
//    }
    return nil;
}

-(NSString*)getCostumeID
{
    NSMutableArray *arr = (NSMutableArray *)[userDefaults objectForKey:@"HomeColors"];
    if (arr && [arr count]>0) {
        int index = arc4random() % ([arr count]);
        defaultSearchIndex = index;
        NSDictionary *dic = [arr objectAtIndex:index];
        NSLog(@"footNetWorkDic=%@",dic);
        cumtomerID = [dic objectForKey:@"CostumeID"];
        return cumtomerID;
    }
    else
    {
        return DefaultCostumeID;
    }
}

-(NSString*)getColorCode
{
    NSMutableArray *arr = (NSMutableArray *)[userDefaults objectForKey:@"HomeColors"];
    if (arr && [arr count]>0) {
        if (defaultSearchIndex >= [arr count]) {
            defaultSearchIndex = 0;
        }
        NSDictionary *dic = [arr objectAtIndex:defaultSearchIndex];
        NSMutableArray *codeArr = [dic objectForKey:@"Codes"];
        int index = arc4random() % ([codeArr count]);
        if (index >= [codeArr count]) {
            index = 0;
        }
        NSDictionary *dicCode = [codeArr objectAtIndex:index];
        colorID = [dicCode objectForKey:@"Code"];
        return colorID;
    }
    else
    {
        return DefaultColorCode;
    }
}


-(void)showLoadingView
{
    lv.hidden = NO;
    lv.isStop = NO;
    [lv startAnimation];
}
-(void)hiddenLoadingView
{
    lv.isStop = YES;
    lv.hidden = YES;
}

//- (void)refreshView
//{
//    [self performSelectorInBackground:@selector(footnetwork) withObject:nil];
//}

#pragma mark - Screen Size
//获取ios屏幕大小（去掉状态条）
- (CGSize) screenSize
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    CGSize size = [UIScreen mainScreen].bounds.size;
    UIApplication *application = [UIApplication sharedApplication];
    if (UIInterfaceOrientationIsLandscape(orientation))
    {
        size = CGSizeMake(size.height, size.width);
    }
    if (application.statusBarHidden == NO)
    {
        size.height -= MIN(application.statusBarFrame.size.width, application.statusBarFrame.size.height);
    }
    return size;
}

#pragma mark - Check Wi-Fi & 3G
- (void) reachabilityChanged:(NSNotification *)note
{
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability:curReach];
}


- (void)updateInterfaceWithReachability:(Reachability *)reachability
{
    
    if (reachability == self.internetReachability)
    {
        [self configureTextField:reachability];
    }
    
    if (reachability == self.wifiReachability)
    {
        [self configureTextField:reachability];
    }
}


- (void)configureTextField:(Reachability *)reachability
{
    NetworkStatus netStatus = [reachability currentReachabilityStatus];
    BOOL connectionRequired = [reachability connectionRequired];
    NSString* statusString = @"";
    
    switch (netStatus)
    {
        case NotReachable:        {
            
            break;
        }
        case ReachableViaWWAN:        {
            NSLog(@"连接到3G了");
            SXModel *model=[SXModel shareModel];
            model.wifi=NO;
            model.scrolled=NO;
            [self.collectionView reloadData];
            statusString = NSLocalizedString(@"Reachable WWAN", @"");
            break;
        }
        case ReachableViaWiFi:        {
            NSLog(@"连接到Wi-Fi了");
            SXModel *model=[SXModel shareModel];
            model.wifi=YES;
            model.scrolled=YES;
            [self.collectionView reloadData];
            statusString= NSLocalizedString(@"Reachable WiFi", @"");
            break;
        }
    }
    
    if (connectionRequired)
    {
        NSString *connectionRequiredFormatString = NSLocalizedString(@"%@, Connection Required", @"Concatenation of status string with connection requirement");
        statusString= [NSString stringWithFormat:connectionRequiredFormatString, statusString];
    }
}

#pragma mark - search string operation

-(void)addSearchObjectWithLevel1:(NSString*)level1 withLevel2:(NSString*)level2 withLevel2Key:(NSDictionary*)level2Key
{
    [self saveSearchDic];
    NSMutableDictionary *searchObj = [[NSMutableDictionary alloc] init];
    [searchObj setObject:level1 forKey:@"l1"];
    [searchObj setObject:level2 forKey:@"l2"];
    [searchObj setObject:level2Key forKey:@"l2key"];
    NSMutableDictionary *colorDic1 = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *chunseDic = [[NSMutableDictionary alloc] init];
    if ([level2 isEqualToString:@"121"]) {
        [colorDic1 setObject:@"touming" forKey:@"colorType"];
        [colorDic1 setObject:chunseDic forKey:@"touming"];
    }
    else
    {
        [colorDic1 setObject:@"chunse" forKey:@"colorType"];
        [colorDic1 setObject:chunseDic forKey:@"chunse"];
    }

    [searchObj setObject:colorDic1 forKey:@"color"];

    [SearchDic setObject:searchObj forKey:level2];
    
    
}

-(void)saveSearchDic
{
    if (isNewSearch) {
        NSMutableArray *arr = (NSMutableArray *)[userDefaults objectForKey:@"SearchArr"];
        if (!arr) {
            arr = [[NSMutableArray alloc] init];
        }
        //[arr addObject:SearchDic];
        NSMutableArray *arrM = [[NSMutableArray alloc] initWithArray:arr];
        //[arrM addObject:SearchDic];
        [arrM insertObject:SearchDic atIndex:0];
        if ([arrM count]>10) {
            arrM = (NSMutableArray *)[arrM subarrayWithRange:NSMakeRange(0, 10)];
        }
        //NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:SearchDic, nil];
        if ([[SearchDic allKeys] count]>0) {
            [userDefaults setObject:arrM forKey:@"SearchArr"];
        }
        
        //[SearchDic removeAllObjects];
        SearchDic = [[NSMutableDictionary alloc] init];
    }
}

#pragma mark - database operation
-(void)initDataFromDB
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        NSString *sql = @"select * from Pic_BelongsType";
        FMResultSet *result = [db executeQuery:sql];
        
        top2KeyValue = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [top2KeyValue removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"id"];
            
            NSString *name = [result stringForColumn:@"Name"];
            [_mutableDictionayData setObject:name forKey:@"Name"];
            
            NSString *icon = [result stringForColumn:@"Icon"];
            [_mutableDictionayData setObject:icon forKey:@"Icon"];
            
            NSString *costumeID = [result stringForColumn:@"CostumeID"];
            [_mutableDictionayData setObject:costumeID forKey:@"CostumeID"];
            
            [top2KeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%@%@.png",costumeID,icon]];
            
        }
        
        //手动添加马甲
//        if (![top2KeyValue valueForKey:[NSString stringWithFormat:@"12s1_majia.png"]]) {
//            NSLog(@"添加马甲!!!!!!");
//            _mutableDictionayData = [[NSMutableDictionary alloc] init];
//            
//            [_mutableDictionayData setObject:@"129" forKey:@"id"];
//            
//            [_mutableDictionayData setObject:@"马甲" forKey:@"Name"];
//            
//            [_mutableDictionayData setObject:@"s1_majia" forKey:@"Icon"];
//            
//            [_mutableDictionayData setObject:@"12" forKey:@"CostumeID"];
//            
//            [top2KeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"12s1_majia.png"]];
//        }
        
        [db close];
    }
}

-(void)dataFromDBToKS1
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
    if ([clothesDic objectForKey:@"xijie"]) {
        [self.kuanshi1tv reloadData];
        return;
    }
    else if ([db open]) {
    NSString *sql = [NSString stringWithFormat:@"select distinct bs.ID,bs.Name from [BelongsStyle_DetailStyle] bsds inner join [Pic_BelongsStyle] bs on bs.ID = bsds.[BelongsStyleId] where bsds.BelongsTypeID=%@ and bsds.Female_DetailStyleId is not null",[filerDetailView getCheckL2Key]];
        FMResultSet *result = [db executeQuery:sql];
        
        NSMutableDictionary *topKeyValue1 = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [topKeyValue1 removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *name = [result stringForColumn:@"Name"];
            [_mutableDictionayData setObject:name forKey:@"Name"];
            
            [topKeyValue1 setValue:_mutableDictionayData forKey:name];
        }
        
        [clothesDic setObject:topKeyValue1 forKey:@"xijie"];
        [db close];
        [self.kuanshi1tv reloadData];
    }
    
}

-(void)dataFromDBToKS2:(NSString*)strID
{
    [self readyDatabse];
    NSLog(@"strID%@",strID);
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
    NSMutableDictionary *topKeyValue1 = (NSMutableDictionary *)[clothesDic objectForKey:@"xijie"];
    NSLog(@"topKeyValue1%@",topKeyValue1);
    NSMutableDictionary *detailTopKeyValue1 = (NSMutableDictionary*)[topKeyValue1 objectForKey:kuanshi1tvChoiceKey];
    NSLog(@"detail%@",detailTopKeyValue1);
    if ([detailTopKeyValue1 objectForKey:@"l4detail"]) {
        [self.kuanshi2tv reloadData];
        return;
    }
    else if ([db open]) {
        NSString *sql = [NSString stringWithFormat:@"select distinct ds.ID,ds.Name from [BelongsStyle_DetailStyle] beds inner join [Pic_DetailStyle] ds on ds.ID=beds.Female_DetailStyleId where beds.BelongsStyleId=%@ and  beds.BelongsTypeID=%@ and beds.Female_DetailStyleId is not null", strID,[filerDetailView getCheckL2Key]];
        FMResultSet *result = [db executeQuery:sql];
        
        NSMutableDictionary *secKeyValue1 = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [secKeyValue1 removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *name = [result stringForColumn:@"Name"];
            [_mutableDictionayData setObject:name forKey:@"Name"];
            
            [secKeyValue1 setValue:_mutableDictionayData forKey:name];
        }
        
        [db close];
        [detailTopKeyValue1 setObject:secKeyValue1 forKey:@"l4detail"];
        NSLog(@"detailTopValue1%@",detailTopKeyValue1);
        if ([secKeyValue1 count]>0) {
            //[self.view addSubview:ksDetailView];
            [self.kuanshi2tv reloadData];
        }
    }
    
}

-(void)dataFromDBYanseWith:(int)type
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        NSString *sql =  [NSString stringWithFormat:@"select * from yanse where Type=%d",type];
        FMResultSet *result = [db executeQuery:sql];
        
        yanseDic = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [yanseDic removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *valueid = [result stringForColumn:@"ValueID"];
            [_mutableDictionayData setObject:valueid forKey:@"ValueID"];
            
            NSString *name = [result stringForColumn:@"Name"];
            [_mutableDictionayData setObject:name forKey:@"Name"];
            
            NSString *icon = [result stringForColumn:@"Icon"];
            [_mutableDictionayData setObject:icon forKey:@"Icon"];
            
            NSString *extValue = [result stringForColumn:@"ExtValue"];
            [_mutableDictionayData setObject:extValue forKey:@"ExtValue"];
            
            [yanseDic setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%d%@",type,icon]];
        }
        
        [db close];
    }
}

-(NSString *)dataFromDBCostume:(NSString *)iconName which:(BOOL)which
{
    NSString *name=nil;
    NSString *icon=nil;
    NSString *ret=nil;
    
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        if (!which) {
            NSString *sql =  [NSString stringWithFormat:@"select * from Pic_Costume where ID=%d",[cumtomerID intValue]];
            FMResultSet *result = [db executeQuery:sql];
            while ([result next]) {
                name = [result stringForColumn:@"Name"];
                ret=name;
                //            if ([name isEqualToString:@"上装二层"] || [name isEqualToString:@"上装三层"] || [name isEqualToString:@"披戴类"]) {
                //                name=[name substringToIndex:2];
                //            }
            }
            [db close];
            
        } else if (which){
            NSString *sql =  [NSString stringWithFormat:@"select * from Pic_Costume where Name=%@",iconName];
            FMResultSet *result = [db executeQuery:sql];
            while ([result next]) {
                icon = [result stringForColumn:@"Icon"];
                ret=icon;
            }
            [db close];
        }
    }
    return ret;
}

-(NSString *)dataFromDBForIcon:(NSString *)iconName
{
    NSString *icon=nil;
    
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        NSString *sql =  [NSString stringWithFormat:@"select * from Pic_Costume where Name=%@",iconName];
        FMResultSet *result = [db executeQuery:sql];
        while ([result next]) {
            icon = [result stringForColumn:@"Icon"];
        }
        
        [db close];
    }
    
    return icon;
}

-(void)dataFromWenziDB
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        NSString *sql =  [NSString stringWithFormat:@"select * from wenzi"];
        FMResultSet *result = [db executeQuery:sql];
        wenziDic = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
        [wenziDic removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *desc = [result stringForColumn:@"desc"];
            [_mutableDictionayData setObject:desc forKey:@"desc"];
            
            NSString *icon = [result stringForColumn:@"Icon"];
            [_mutableDictionayData setObject:icon forKey:@"Icon"];
            
            NSString *extValue = [result stringForColumn:@"ExtValue"];
            [_mutableDictionayData setObject:extValue forKey:@"ExtValue"];
            
            [wenziDic setValue:_mutableDictionayData forKey:icon];
        }
        
        [db close];
    }
}

-(NSMutableDictionary*)dataFromDBToColor:(int)colorIndexValue
{
    [self readyDatabse];
    FMDatabase *db = [FMDatabase databaseWithPath:path];
    if ([db open]) {
        NSString *sql =  [NSString stringWithFormat:@"select * from DetailColor1 where Maincolor=%d",colorIndexValue];
        FMResultSet *result = [db executeQuery:sql];
        
//        if (index==0) {
//            ColorThdKeyValueB = [[NSMutableDictionary alloc] init];
//        } else if(index==1){
//            ColorThdKeyValue = [[NSMutableDictionary alloc] init];
//        } else if (index==2){
//            ColorThdKeyValueA = [[NSMutableDictionary alloc] init];
//        }
        ColorThdKeyValue = [[NSMutableDictionary alloc] init];
        NSMutableDictionary *_mutableDictionayData = [[NSMutableDictionary alloc] init];
//        if (index==0) {
//            [ColorThdKeyValueB removeAllObjects];
//        } else if(index==1){
//            [ColorThdKeyValue removeAllObjects];
//        } else if (index==2){
//            [ColorThdKeyValueA removeAllObjects];
//        }
        [ColorThdKeyValue removeAllObjects];
        [_mutableDictionayData removeAllObjects];
        while ([result next]) {
            _mutableDictionayData = [[NSMutableDictionary alloc] init];
            NSString *sid = [result stringForColumn:@"ID"];
            [_mutableDictionayData setObject:sid forKey:@"ID"];
            
            NSString *webcolorvalue = [result stringForColumn:@"webcolorvalue"];
            [_mutableDictionayData setObject:webcolorvalue forKey:@"webcolorvalue"];
            
            NSString *rvalue = [result stringForColumn:@"Rvalue"];
            [_mutableDictionayData setObject:rvalue forKey:@"Rvalue"];
            
            NSString *gvalue = [result stringForColumn:@"Gvalue"];
            [_mutableDictionayData setObject:gvalue forKey:@"Gvalue"];
            
            NSString *bvalue = [result stringForColumn:@"Bvalue"];
            [_mutableDictionayData setObject:bvalue forKey:@"Bvalue"];
            
//            if (index==0) {
//                [ColorThdKeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%d",(int)[[ColorThdKeyValueB allKeys] count]+1]];
//            } else if(index==1){
//                [ColorThdKeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%d",(int)[[ColorThdKeyValue allKeys] count]+1]];
//            } else if (index==2){
//                [ColorThdKeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%d",(int)[[ColorThdKeyValueA allKeys] count]+1]];
//            }
             [ColorThdKeyValue setValue:_mutableDictionayData forKey:[NSString stringWithFormat:@"%d",(int)[[ColorThdKeyValue allKeys] count]+1]];
        }
        
        [db close];
//        if (index==0) {
//            return ColorThdKeyValueB;
//        } else if (index==1){
//            return ColorThdKeyValue;
//        } else if (index==2){
//            return ColorThdKeyValueA;
//        }
        return ColorThdKeyValue;
        
    }
    return nil;
}

- (void)readyDatabse {
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"dd21.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    [self getPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dd21.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

- (void)getPath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    path = [documentsDirectory stringByAppendingPathComponent:@"dd21.sqlite"];
}
#pragma mark 路径



#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section {
    //return 30;
    SXModel *model=[SXModel shareModel];
    NSLog(@"------numberOfItemsInSection-----%lu",(unsigned long)[model.infoArr count]);
    if (self.collectionView == collectionView) {
        return [model.infoArr count];
    }
    else if (self.level2CV == collectionView)
    {
        return [self.level2CVinfoArrays count];
    }
    else if (self.filterLevel2CV == collectionView)
    {
        return [self.filterLevel2CVinfoArrays count];
    }
    else if (self.filterLevel3CV == collectionView)
    {
        return [self.filterLevel3CVinfoArrays count];
    }
    else if (self.filterLevel3CAno == collectionView)
    {
        return [self.filterLevel5CVinfoArrays count];
    }
    else if (self.filterLevel3CBef == collectionView)
    {
        return [self.filterLevel3CVinfoArrays count];
    }
    else if (self.filterLevel4CV == collectionView)
    {
        return [[ColorThdKeyValue allKeys] count];
    }
    else if (self.filterLevel4CBef == collectionView)
    {
        return [[ColorThdKeyValue allKeys] count];
    }
    else if (self.filterLevel4CAno == collectionView)
    {
        return [[ColorThdKeyValue allKeys] count];
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    if (self.collectionView == collectionView) {
        ContentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
        SXModel *model=[SXModel shareModel];
        NSDictionary *infodic = [model.infoArr objectAtIndex:indexPath.row];
        NSString *strColor = [infodic objectForKey:@"AvgColor"];
        //UIImage *defaultImg = [self imageWithColor:[self colorWithHexString:strColor]];
        UIImage *defaultImg = [self imageColor:[self colorWithHexString:strColor] size:CGSizeMake(cell.frame.size.width, cell.frame.size.height)];
        if (self.defaultImgArr.count!=0) {
            BOOL same=NO;
            for (int i=0; i<self.defaultImgArr.count; i++) {
                if ([defaultImg isEqual:[self.defaultImgArr objectAtIndex:i]]) {
                    same=YES;
                }
            }
            
            if (!same) {
                [self.defaultImgArr addObject:defaultImg];
            }
        } else
            [self.defaultImgArr addObject:defaultImg];
        
        
//        UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, h/(w/150.f))];
//        [imgv sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",@"http://115.28.80.218/downloadImg/",[infodic objectForKey:@"Pic_Name"]]] placeholderImage:defaulImg]; // @"http://115.28.80.218/downloadImg/"
//        [cell addSubview:imgv];
        
        
        
        if ([[infodic objectForKey:@"Name"] isEqualToString:@"loading"]) {
            cell.imageView.image=defaultImg;
        } else if ([[infodic objectForKey:@"Name"] isEqualToString:@"kidding"]){
            cell.alpha=0;
            cell.hidden=YES;
            cell.userInteractionEnabled=NO;
        } else {
            
//            SXModel *model=[SXModel shareModel];
//            model.infoArr=model.infoArr;
            [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@@90q_%fw.jpg",[self getImageUrl],[infodic objectForKey:@"Name"],[self screenSize].width]] placeholderImage:defaultImg index:(int)indexPath.row];
            //cell.label.text=[[infodic objectForKey:@"ID"] stringValue];
            
            
            if (!model.wifi && !model.scrolled) {
                [cell.imageView sd_cancelCurrentImageLoad];
            }
        }
        
        
        return cell;
    }
    
    else if(self.filterLevel2CV == collectionView)
    {
        SecMCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kSecListCellID forIndexPath:indexPath];
        cell.imageView.image = [UIImage imageNamed:[self.filterLevel2CVinfoArrays objectAtIndex:indexPath.row]];
        NSString *titleName = [self.filterLevel2CVinfoArrays objectAtIndex:indexPath.row];
        cell.titleName.text = NSLocalizedString(titleName,@"");
        cell.imageView.contentMode = UIViewContentModeCenter;
        cell.checkIV.hidden = NO;
        if (m_filterSubmenutype == EM_FST_wZhuseban || m_filterSubmenutype==EM_FST_Peiseban || m_filterSubmenutype==EM_FST_touMingSeban ) {
            cell.titleName.hidden=YES;
        } else
            cell.titleName.hidden=NO;
        
        NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
        NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
        switch (m_filterSubmenutype) {
            case EM_FST_YanSeshuxing:
            {
                NSMutableDictionary *yanse = [colordic objectForKey:@"yanse"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                if ([yanse objectForKey:key]) {
                    [UIView animateWithDuration:1.0 animations:^{
                        cell.checkIV.hidden = NO;
                    }];
                    
                }
                else
                {
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_wZhuseban:
            {
                NSMutableDictionary *wZhuseban = [colordic objectForKey:@"zhuse"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                //int count = (int)[wZhuseban count];
                if ([wZhuseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_Peiseban:
            {
                NSMutableDictionary *peiseban = [colordic objectForKey:@"peise"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                //int count = (int)[wZhuseban count];
                if ([peiseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_touMingSeban:
            {
                NSMutableDictionary *peiseban = [colordic objectForKey:@"touming"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                //int count = (int)[wZhuseban count];
                if ([peiseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                }
            }
            default:
                break;
        }
        
        return cell;
    }
    else if(self.filterLevel3CV == collectionView)
    {
        FilterLevel3CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel3CellID forIndexPath:indexPath];
        cell.imageView.image = [UIImage imageNamed:[self.filterLevel3CVinfoArrays objectAtIndex:indexPath.row]];
        cell.imageView.contentMode = UIViewContentModeCenter;
        cell.checkIV.hidden = NO;
        if (m_filterSubmenutype == EM_FST_Zhuseban || m_filterSubmenutype==EM_FST_Chunseban) {
            cell.checkIV.hidden = YES;
            
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];

            switch (m_filterSubmenutype) {
                case EM_FST_Zhuseban:
                {
                    NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                    NSArray *keyArray = [Zhuseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }

                    }

                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                case EM_FST_Chunseban:
                {
                    NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                    NSArray *keyArray = [chunseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }
                        
                    }
                    
                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                default:
                    break;
            }
            
            //cell.countLbl.hidden = NO;
        } else if (m_filterSubmenutype == EM_FST_wZhuseban || m_filterSubmenutype==EM_FST_touMingSeban ) {
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
            
            switch (m_filterSubmenutype) {
                case EM_FST_wZhuseban:
                {
                    NSMutableDictionary *wZhuseban = [colordic objectForKey:@"zhuse"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([wZhuseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                    break;
                case EM_FST_touMingSeban:
                {
                    NSMutableDictionary *peiseban = [colordic objectForKey:@"touming"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([peiseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                default:
                    break;
            }
        }
        
        return cell;
    }
    else if(self.filterLevel3CBef == collectionView)
    {
        FilterLevel3CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel6CellID forIndexPath:indexPath];
        cell.imageView.image = [UIImage imageNamed:[self.filterLevel3CVinfoArrays objectAtIndex:indexPath.row]];
        cell.imageView.contentMode = UIViewContentModeCenter;
        cell.checkIV.hidden = NO;
        if (m_filterSubmenutype == EM_FST_Zhuseban || m_filterSubmenutype==EM_FST_Chunseban) {
            cell.checkIV.hidden = YES;
            
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
            
            switch (m_filterSubmenutype) {
                case EM_FST_Zhuseban:
                {
                    NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                    NSArray *keyArray = [Zhuseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }
                        
                    }
                    
                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                case EM_FST_Chunseban:
                {
                    NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                    NSArray *keyArray = [chunseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }
                        
                    }
                    
                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                default:
                    break;
            }
            
            //cell.countLbl.hidden = NO;
        } else if (m_filterSubmenutype == EM_FST_wZhuseban || m_filterSubmenutype==EM_FST_touMingSeban ) {
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
            
            switch (m_filterSubmenutype) {
                case EM_FST_wZhuseban:
                {
                    NSMutableDictionary *wZhuseban = [colordic objectForKey:@"zhuse"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([wZhuseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                    break;
                case EM_FST_touMingSeban:
                {
                    NSMutableDictionary *peiseban = [colordic objectForKey:@"touming"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([peiseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                default:
                    break;
            }
        }
        
        return cell;
    }
    
    else if(self.filterLevel3CAno == collectionView)
    {
        FilterLevel3CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel5CellID forIndexPath:indexPath];
        cell.imageView.image = [UIImage imageNamed:[self.filterLevel5CVinfoArrays objectAtIndex:indexPath.row]];
        cell.imageView.contentMode = UIViewContentModeCenter;
        cell.checkIV.hidden = NO;
        if (m_filterSubmenutype == EM_FST_Zhuseban || m_filterSubmenutype==EM_FST_Chunseban) {
            cell.checkIV.hidden = YES;
            
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
            
            switch (m_filterSubmenutype) {
                case EM_FST_Zhuseban:
                {
                    NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                    NSArray *keyArray = [Zhuseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }
                        
                    }
                    
                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                case EM_FST_Chunseban:
                {
                    NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                    NSArray *keyArray = [chunseban allKeys];
                    int count = 0;
                    if ([keyArray count]>0) {
                        for (int i =0 ; i < [keyArray count]; i++) {
                            NSString *strValue = (NSString*)[keyArray objectAtIndex:i];
                            if ([strValue length]>7) {
                                NSString *numValue = [strValue substringFromIndex:7];
                                if (indexPath.row == ([numValue integerValue]-1)) {
                                    count = count +1;
                                }
                            }
                            
                        }
                        
                    }
                    
                    cell.countLbl.text = [NSString stringWithFormat:@"%d",count];
                    if (count==0) {
                        cell.countLbl.hidden = YES;
                    }
                    else
                        cell.countLbl.hidden = NO;
                }
                    break;
                default:
                    break;
            }
            
            //cell.countLbl.hidden = NO;
        } else if (m_filterSubmenutype == EM_FST_wZhuseban || m_filterSubmenutype==EM_FST_touMingSeban ) {
            
            NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
            NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
            
            switch (m_filterSubmenutype) {
                case EM_FST_wZhuseban:
                {
                    NSMutableDictionary *wZhuseban = [colordic objectForKey:@"zhuse"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([wZhuseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                    break;
                case EM_FST_touMingSeban:
                {
                    NSMutableDictionary *peiseban = [colordic objectForKey:@"touming"];
                    NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                    //int count = (int)[wZhuseban count];
                    if ([peiseban objectForKey:key]) {
                        cell.checkIV.hidden = NO;
                    }
                    else
                    {
                        cell.checkIV.hidden = YES;
                    }
                }
                default:
                    break;
            }
        }
        
        return cell;
    }
#pragma mark - 4CV
    else if(self.filterLevel4CV == collectionView)
    {
        DetailColorCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel4CellID forIndexPath:indexPath];
        NSDictionary *dic1 = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        float r = [[dic1 objectForKey:@"Rvalue"] floatValue];
        float g = [[dic1 objectForKey:@"Gvalue"] floatValue];
        float b = [[dic1 objectForKey:@"Bvalue"] floatValue];
        if (self.iPhone) {
            //[Utility showHelpWith:@"help4-4s@2x.png"];
        } else
            //[Utility showHelpWith:@"help4.png"];
        
        cell.colorView.backgroundColor = [[UIColor alloc] initWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1.0f];
        cell.checkIV.hidden = NO;
//        if (checkint != indexPath.row) {
//            cell.checkIV.hidden = YES;
//        }
        
        NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
        NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
        NSMutableDictionary *dic = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        NSString *checkColor = [dic objectForKey:@"webcolorvalue"];
        
        SXModel *model=[SXModel shareModel];
        switch (m_filterSubmenutype) {
            case EM_FST_Zhuseban:
            {
                NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNo];
                if ([Zhuseban objectForKey:key]) {
                    NSLog(@"checkHiddenNo");
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    NSLog(@"checkHiddenYes");
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_Chunseban:
            {
                NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNo];
                //int count = (int)[wZhuseban count];
                if ([chunseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                    
                }
            }
                break;
            case EM_FST_touMingSeban:
            {
                NSMutableDictionary *toumingseban = [colordic objectForKey:@"touming"];
                
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNo];
                //int count = (int)[wZhuseban count];
                if ([toumingseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                    
                }
            }
                break;
            default:
                break;
        }
        return cell;
    }
    
    else if(self.filterLevel4CBef == collectionView)
    {
        DetailColorCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel7CellID forIndexPath:indexPath];
        NSDictionary *dic1 = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        float r = [[dic1 objectForKey:@"Rvalue"] floatValue];
        float g = [[dic1 objectForKey:@"Gvalue"] floatValue];
        float b = [[dic1 objectForKey:@"Bvalue"] floatValue];
        if (self.iPhone) {
            //[Utility showHelpWith:@"help4-4s@2x.png"];
        } else
            //[Utility showHelpWith:@"help4.png"];
        
        cell.colorView.backgroundColor = [[UIColor alloc] initWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1.0f];
        cell.checkIV.hidden = NO;
        //        if (checkint != indexPath.row) {
        //            cell.checkIV.hidden = YES;
        //        }
        
        NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
        NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
        NSMutableDictionary *dic = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        NSString *checkColor = [dic objectForKey:@"webcolorvalue"];
        
        SXModel *model=[SXModel shareModel];
        switch (m_filterSubmenutype) {
            case EM_FST_Zhuseban:
            {
                NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNoB];
                if ([Zhuseban objectForKey:key]) {
                    NSLog(@"checkHiddenNo");
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    NSLog(@"checkHiddenYes");
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_Chunseban:
            {
                NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNoB];
                //int count = (int)[wZhuseban count];
                if ([chunseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                    
                }
            }
                break;
            default:
                break;
        }
        return cell;
    }
    
    else if(self.filterLevel4CAno == collectionView)
    {
        DetailColorCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kLevel8CellID forIndexPath:indexPath];
        NSDictionary *dic1 = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        float r = [[dic1 objectForKey:@"Rvalue"] floatValue];
        float g = [[dic1 objectForKey:@"Gvalue"] floatValue];
        float b = [[dic1 objectForKey:@"Bvalue"] floatValue];
        if (self.iPhone) {
            //[Utility showHelpWith:@"help4-4s@2x.png"];
        } else
            //[Utility showHelpWith:@"help4.png"];
        
        cell.colorView.backgroundColor = [[UIColor alloc] initWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1.0f];
        cell.checkIV.hidden = NO;
        //        if (checkint != indexPath.row) {
        //            cell.checkIV.hidden = YES;
        //        }
        
        NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
        NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
        NSMutableDictionary *dic = [ColorThdKeyValue objectForKey:[NSString stringWithFormat:@"%d",(int)indexPath.row+1]];
        NSString *checkColor = [dic objectForKey:@"webcolorvalue"];
        
        SXModel *model=[SXModel shareModel];
        switch (m_filterSubmenutype) {
            case EM_FST_Zhuseban:
            {
                NSMutableDictionary *Zhuseban = [colordic objectForKey:@"zhuse"];
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNoA];
                if ([Zhuseban objectForKey:key]) {
                    NSLog(@"checkHiddenNo");
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    NSLog(@"checkHiddenYes");
                    cell.checkIV.hidden = YES;
                }
            }
                break;
            case EM_FST_Chunseban:
            {
                NSMutableDictionary *chunseban = [colordic objectForKey:@"chunse"];
                
                NSString *key = [NSString stringWithFormat:@"%@%@",checkColor,model.parentNoA];
                //int count = (int)[wZhuseban count];
                if ([chunseban objectForKey:key]) {
                    cell.checkIV.hidden = NO;
                }
                else
                {
                    cell.checkIV.hidden = YES;
                    
                }
            }
                break;
            default:
                break;
        }
        return cell;
    }
    
    return nil;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView
                   layout:(HomeViewFlowLayout *)collectionViewLayout
 heightForItemAtIndexPath:(NSIndexPath *)indexPath {
    //return [self.cellHeights[indexPath.section + 1 * indexPath.item] floatValue];
    SXModel *model=[SXModel shareModel];
    NSDictionary *infodic = [model.infoArr objectAtIndex:indexPath.row];
    float h = [[infodic objectForKey:@"Height"] floatValue];
    float w = [[infodic objectForKey:@"Width"] floatValue];
    //NSLog(@"--------- h = %f  w = %f",h,w);
    return h/(w/150.f);
}
- (void)collectionView:(UICollectionView *)collectionView
            didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.collectionView == collectionView) {
        SXModel *model=[SXModel shareModel];
        NSDictionary *infodic = [model.infoArr objectAtIndex:indexPath.row];
        //[self clockStop];
        if ([[infodic valueForKey:@"download"] boolValue]) {
            HomeDetailViewController *hvc = [[HomeDetailViewController alloc] initWithNibName:@"HomeDetailViewController" bundle:nil withURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@@90q_%fh.jpg",[self getImageUrl],[infodic objectForKey:@"Name"],[self screenSize].height]] withSource:[infodic objectForKey:@"SourceUrl"] index:indexPath.row];
            
            [self presentViewController:hvc animated:YES completion:^{
            }];
        }
        
        
    }
    else if(self.filterLevel2CV == collectionView)
    {
        NSMutableDictionary *clothesDic = (NSMutableDictionary *)[SearchDic objectForKey:[filerDetailView getCheckL2Key]];
        NSMutableDictionary *colordic = (NSMutableDictionary*)[clothesDic objectForKey:@"color"];
        NSString *titleName = [self.filterLevel2CVinfoArrays objectAtIndex:indexPath.row];
        switch (m_filterSubmenutype) {
            case EM_FST_YanSeshuxing:
            {
                NSMutableDictionary *yanse = [colordic objectForKey:@"yanse"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                if ([yanse objectForKey:key]) {
                    SXModel *model=[SXModel shareModel];
                    NSMutableArray *tuanArr=[model.selectedTuanDic valueForKey:model.tuanKey];
                    for (int i=0; i<tuanArr.count; i++) {
                        NSDictionary *dic=(NSDictionary *)[tuanArr objectAtIndex:i];
                        if ([[dic valueForKey:@"Icon"] isEqualToString:[[yanse objectForKey:key] valueForKey:@"Icon"]]) {
                            if (i==0) {
                                [tuanArr removeObjectAtIndex:0];
                            } else
                                [tuanArr removeObject:dic];
                        }
                    }
                    [yanse removeObjectForKey:key];
                    
                } else {
                    if ([yanse count]>1) {
                        return;
                    }
                    
                    //NSLog(@"yanseDic=%@",yanseDic);
                    NSMutableDictionary *tmpDic = [yanseDic objectForKey:[NSString stringWithFormat:@"%d%@",m_filtertype,titleName]];
                    //NSLog(@"tmpDic=%@",tmpDic);
                    //[yanse setObject:[tmpDic objectForKey:@"ValueID"] forKey:key];
                    [yanse setObject:tmpDic forKey:key];
                    
                    SXModel *model=[SXModel shareModel];
                    NSMutableArray *tuanArr=[model.selectedTuanDic valueForKey:model.tuanKey];
                    [tuanArr addObject:tmpDic];
                    NSLog(@"---tuanArr=%@",tuanArr);
                    NSLog(@"---aftertuanDic=%@",model.selectedTuanDic);
                }
                
                self.selectedView1.image=nil;
                self.selectedView2.image=nil;
                self.selectedView3.image=nil;
                self.selectedView4.image=nil;
                
                SXModel *model=[SXModel shareModel];
                //NSLog(@"selectedTuanArr=%@",model.selectedTuanArr);
                NSMutableArray *tuanArr=[model.selectedTuanDic valueForKey:model.tuanKey];
                if (tuanArr.count>0) {
                    for (int i=0; i<tuanArr.count; i++) {
                        NSDictionary *dic=(NSDictionary *)[tuanArr objectAtIndex:i];
                        switch (i) {
                            case 0:{
                                if (model.zhuse) {
                                    self.selectedView1.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[dic valueForKey:@"Icon"]]];
                                } else {
                                    self.selectedView3.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[dic valueForKey:@"Icon"]]];
                                }
                                
                            }
                                break;
                            case 1:{
                                if (model.zhuse) {
                                    self.selectedView2.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[dic valueForKey:@"Icon"]]];
                                } else{
                                    self.selectedView4.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[dic valueForKey:@"Icon"]]];
                                }
                                
                            }
                                break;
                            default:
                                break;
                        }
                    }
                }
                
            }
                break;
            case EM_FST_wZhuseban:
            {
                NSMutableDictionary *wZhuseban = [colordic objectForKey:@"zhuse"];
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                if ([wZhuseban objectForKey:key]) {
                    [wZhuseban removeObjectForKey:key];
                }
                else
                {
                    if ([wZhuseban count]>4) {
                        return;
                    }
                    NSMutableDictionary *tmpDic = [wenziDic objectForKey:titleName];
                    //[wZhuseban setObject:[tmpDic objectForKey:@"ExtValue"] forKey:key];
                    [wZhuseban setObject:tmpDic forKey:key];
                }
            }
                break;
            case EM_FST_Peiseban:
            {
                NSMutableDictionary *peiseban = [colordic objectForKey:@"peise"];
                
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                //int count = (int)[wZhuseban count];
                if ([peiseban objectForKey:key]) {
                    SXModel *model=[SXModel shareModel];
                    NSMutableArray *peiseArr=[model.selectedPeiseDic valueForKey:model.tuanKey];
                    for (int i=0; i<peiseArr.count; i++) {
                        NSDictionary *dic=(NSDictionary *)[peiseArr objectAtIndex:i];
                        if ([[dic valueForKey:@"Icon"] isEqualToString:[[peiseban objectForKey:key] valueForKey:@"Icon"]]) {
                            if (i==0) {
                                [peiseArr removeObjectAtIndex:0];
                            } else
                                [peiseArr removeObject:dic];
                        }
                    }
                    [peiseban removeObjectForKey:key];
                    
                } else {
                    if ([peiseban count]>1) {
                        return;
                    }
                    NSMutableDictionary *tmpDic = [wenziDic objectForKey:titleName];
                    NSLog(@"tmpDic=%@",tmpDic);
                    //[peiseban setObject:[tmpDic objectForKey:@"ExtValue"] forKey:key];
                    [peiseban setObject:tmpDic forKey:key];
                    
                    SXModel *model=[SXModel shareModel];
                    NSMutableArray *peiseArr=[model.selectedPeiseDic valueForKey:model.tuanKey];
                    [peiseArr addObject:tmpDic];
                }
                
                self.selectedLab1.text=nil;
                self.selectedLab2.text=nil;
                
                SXModel *model=[SXModel shareModel];
                NSMutableArray *peiseArr=[model.selectedPeiseDic valueForKey:model.tuanKey];
                if (peiseArr.count>0) {
                    for (int i=0; i<peiseArr.count; i++) {
                        NSDictionary *dic=(NSDictionary *)[peiseArr objectAtIndex:i];
                        switch (i) {
                            case 0:{
                                self.selectedLab1.text=[dic valueForKey:@"desc"];
                            }
                                break;
                            case 1:{
                                self.selectedLab2.text=[dic valueForKey:@"desc"];
                            }
                                break;
                            default:
                                break;
                        }
                    }
                }
            
            }
                break;
            case EM_FST_touMingSeban:
            {
                NSMutableDictionary *peiseban = [colordic objectForKey:@"touming"];
                
                NSString *key = [NSString stringWithFormat:@"%d",(int)indexPath.row];
                //int count = (int)[wZhuseban count];
                if ([peiseban objectForKey:key]) {
                    [peiseban removeObjectForKey:key];
                }
                else
                {
                    if ([peiseban count]>0) {
                        return;
                    }
                    NSMutableDictionary *tmpDic = [wenziDic objectForKey:titleName];
                    //[peiseban setObject:[tmpDic objectForKey:@"ExtValue"] forKey:key];
                    [peiseban setObject:tmpDic forKey:key];
                }
            }
                break;
            default:
                break;
        }
        NSArray *indexpaths = [[NSArray alloc] initWithObjects:indexPath, nil];
        [self.filterLevel2CV reloadItemsAtIndexPaths:indexpaths];
    }
    
}
#pragma mark - FilterLevel3CV Select
    
#pragma mark -

//- (NSMutableArray *)cellHeights {
//    if (!_cellHeights) {
//        _cellHeights = [NSMutableArray arrayWithCapacity:900];
//        for (NSInteger i = 0; i < 900; i++) {
//            _cellHeights[i] = @(arc4random()%100*2+100);
//        }
//    }
//    return _cellHeights;
//}

- (UIImage *)imageColor:(UIColor *)color size:(CGSize)size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

#pragma mark - collectionRefresh
- (void)collectionViewRefresh:(NSMutableArray *)arr
{
    //[self.collectionView insertItemsAtIndexPaths:arr];
    [self.collectionView reloadData];
    isFetchData = NO;
    //[self.collectionView setScrollEnabled:YES];
}

#pragma mark - Fetch Data
//-(void)firstRequest
//{
//    
//    NSString *soapMessage = [NSString stringWithFormat:
//                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
//                             "<soap12:Envelope "
//                             "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
//                             "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
//                             "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
//                             "<soap12:Body>"
//                             "<HomeShowPicture xmlns=\"http://tempuri.org/\">"
//                             "<userid>%@</userid>"
//                             "<userip>%@</userip>"
//                             "<address>%@</address>"
//                             "<date>%@</date>"
//                             "<gender>female</gender>"
//                             "<firstid>%@</firstid>"
//                             "<colorname>%@</colorname>"
//                             "<currentpage>%d</currentpage>"
//                             "<pagesize>%@</pagesize>"
//                             "</HomeShowPicture>"
//                             "</soap12:Body>"
//                             "</soap12:Envelope>", [[NSUserDefaults standardUserDefaults]valueForKey:@"UserID"],@"",@"",@"",@"4",@"#FF0000",1,@"20"];
//    CLog(@"%@",soapMessage);
//    //请求发送到的路径
//    //    NSString *url = [NSString stringWithFormat:@"%@WebService/Watu_WebService.asmx",API_SERVER_URL];
//    NSString *soapActionURL = @"http://tempuri.org/HomeShowPicture";
//    NetWebServiceRequest *request = [NetWebServiceRequest serviceRequestUrl:API_SERVER_URL SOAPActionURL:soapActionURL ServiceMethodName:@"getMobileCodeInfo" SoapMessage:soapMessage];
//    [request startAsynchronous];
//    [request setDelegate:self];
//    self.runningRequest = request;
//}
-(void)footnetwork
{
//    NSString *labelsStr = @"{\"usesituation\":\"\",\"gender\":\"female\",\"wholestyle\":\"\",\"season\":\"\",\"labels\":[{\"tf_labels\":[],\"colors\":{\"type\":\"\",\"colorstyle\":\"\",\"color1\":\"\",\"color\":\"\"},\"speciallabelsid\":{\"str_m\":\"\",\"str_d\":\"\",\"str_s\":\"\"},\"firstid\":\"1\",\"secondid\":5}]}";
    static int ncurrentpage=0;
    
    isHomeSearch=YES;
    
    if (isNewSearch) {
        ncurrentpage = 1;
        SXModel *model=[SXModel shareModel];
        model.wifi=YES;
        
        
        [self getCostumeID];
        [self getColorCode];
        
    } else if (isFetchData) {
        ncurrentpage = currentpage+1;
        SXModel *model=[SXModel shareModel];
        
        if (ncurrentpage > totalpage) {
//            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"消息" message:@"已无数据显示" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
            model.pageOver=YES;
            
        } else
            model.pageOver=NO;
    }
//    else
//    {
//        ncurrentpage = 1;
//        [self getColorCode];
//        [self getCostumeID];
//    }
    
    SXModel *model=[SXModel shareModel];
    if (!model.pageOver) {
        NSString *c1=nil;
        NSString *c2=nil;
        if (![userDefaults valueForKey:@"showWel1.0"]) {
            [userDefaults setObject:@"YES" forKey:@"showWel1.0"];
            c1=@"4";
            c2=@"#FF0000";
            cumtomerID=@"4";
            colorID=@"#FF0000";
        } else {
            NSLog(@"dadada");
            c1=cumtomerID;
            c2=colorID;
        }
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                                 "<soap12:Envelope "
                                 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                                 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                                 "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                                 "<soap12:Body>"
                                 "<HomeShowPicture xmlns=\"http://tempuri.org/\">"
                                 "<userid>%@</userid>"
                                 "<userip>%@</userip>"
                                 "<address>%@</address>"
                                 "<date>%@</date>"
                                 "<gender>female</gender>"
                                 "<firstid>%@</firstid>"
                                 "<colorname>%@</colorname>"
                                 "<currentpage>%d</currentpage>"
                                 "<pagesize>%@</pagesize>"
                                 "</HomeShowPicture>"
                                 "</soap12:Body>"
                                 "</soap12:Envelope>", [[NSUserDefaults standardUserDefaults]valueForKey:@"UserID"],@"",@"",@"",c1,c2,ncurrentpage,@"20"];
        CLog(@"%@",soapMessage);
        //NSLog(@"!!!!!!???!!!%@,%@",cumtomerID,colorID);
        
        //请求发送到的路径
        //    NSString *url = [NSString stringWithFormat:@"%@WebService/Watu_WebService.asmx",API_SERVER_URL];
        NSString *soapActionURL = @"http://tempuri.org/HomeShowPicture";
        NetWebServiceRequest *request = [NetWebServiceRequest serviceRequestUrl:API_SERVER_URL SOAPActionURL:soapActionURL ServiceMethodName:@"getMobileCodeInfo" SoapMessage:soapMessage];
        [request startAsynchronous];
        [request setDelegate:self];
        
        self.runningRequest = request;
    }
    
    if (self.refreshNum==0) {
        [self clockSelectBtn];
    }
    self.refreshNum++;
}

#pragma mark - ArrowAction
- (void)create4CVScrollView
{
    self.scroll3CVView.alpha=0;
    FilterView *filerView = (FilterView*)[self.view viewWithTag:13];
    //[self.filterLevel4CBef reloadData];
    [self.filterLevel4CV reloadData];
    //[self.filterLevel4CAno reloadData];
//    [self.scroll4CVView addSubview:self.filterLevel4CBef];
//    [self.scroll4CVView addSubview:self.filterLevel4CV];
//    [self.scroll4CVView addSubview:self.filterLevel4CAno];
    //[filerView addSubview:self.filterLevel4CBef];
    [filerView addSubview:self.filterLevel4CV];
    //[filerView addSubview:self.filterLevel4CAno];
    
    SXModel *model=[SXModel shareModel];
    NSLog(@"--++--%d",model.sebanIndex);
    if (model.sebanIndex!=16) {
        _swipeR=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight)];
        [_swipeR setDirection:UISwipeGestureRecognizerDirectionRight];
        [filerView addGestureRecognizer:_swipeR];
        
        _swipeL=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)];
        [_swipeL setDirection:UISwipeGestureRecognizerDirectionLeft];
        [filerView addGestureRecognizer:_swipeL];
    
    } else
        self.scroll3CVView.scrollEnabled=NO;
    
    
    //SXModel *model=[SXModel shareModel];
    
//    if (model.sebanIndex==1) {
//        model.anoIndex=2;
//        model.befIndex=16;
//    } else if (model.sebanIndex==16){
//        model.befIndex=15;
//        model.anoIndex=1;
//    } else {
//        model.befIndex=model.sebanIndex-1;
//        model.anoIndex=model.sebanIndex+1;
//    }
    
}

- (void)swipeLeft
{
    CGRect frame=self.filterLevel4CV.frame;
    [UIView animateWithDuration:0.3 animations:^{
        self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x-([self screenSize].width-self.filterLevel4CV.frame.origin.x), self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
        //self.filterLevel4CV.alpha=0;
    } completion:^(BOOL finished) {
        self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x+[self screenSize].width+270, self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
        [self changeColor4];
        [UIView animateWithDuration:0.3 animations:^{
            self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x-270-frame.origin.x, self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
            self.filterLevel4CV.alpha=1;
        } completion:^(BOOL finished) {
            nil;
        }];
    }];
}

- (void)swipeRight
{
    CGRect frame=self.filterLevel4CV.frame;
    [UIView animateWithDuration:0.3 animations:^{
        self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x+270+frame.origin.x, self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
        //self.filterLevel4CV.alpha=0;
    } completion:^(BOOL finished) {
        self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x-270-[self screenSize].width, self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
        [self changeColor2];
        [UIView animateWithDuration:0.3 animations:^{
            self.filterLevel4CV.frame=CGRectMake(self.filterLevel4CV.frame.origin.x+([self screenSize].width-frame.origin.x), self.filterLevel4CV.frame.origin.y, CGRectGetWidth(self.filterLevel4CV.frame), CGRectGetHeight(self.filterLevel4CV.frame));
            self.filterLevel4CV.alpha=1;
        } completion:^(BOOL finished) {
            nil;
        }];
    }];
}

- (void)changeColor1
{
    NSLog(@"changeColor1");
    SXModel *model=[SXModel shareModel];
    
    NSMutableDictionary *mutableDic2 = [self dataFromDBToColor:model.befIndex];
    if (mutableDic2 && [mutableDic2 count]>0) {
        model.parentNoB=[NSString stringWithFormat:@"%d",model.befIndex];
        [self.filterLevel4CBef reloadData];
        FilterView *filerView = (FilterView*)[self.view viewWithTag:13];
        [filerView addSubview:self.filterLevel4CBef];
    }
    //[self performSelector:@selector(changeColor2) withObject:nil afterDelay:0];
    //[self performSelectorOnMainThread:@selector(changeColor2) withObject:nil waitUntilDone:NO];
}

- (void)changeColor2
{
    NSLog(@"changeColor2");
    SXModel *model=[SXModel shareModel];
    if (model.sebanIndex==1) {
        model.sebanIndex=15;
    } else
        model.sebanIndex--;
    NSMutableDictionary *mutableDic2 = [self dataFromDBToColor:model.sebanIndex];
    if (mutableDic2 && [mutableDic2 count]>0) {
        model.parentNo=[NSString stringWithFormat:@"%d",model.sebanIndex];
        [self.filterLevel4CV reloadData];
        //[self.scroll4CVView addSubview:self.filterLevel4CAno];
    }
    //[self performSelector:@selector(changeColor3) withObject:nil afterDelay:0];
    //[self performSelectorOnMainThread:@selector(changeColor3) withObject:nil waitUntilDone:NO];
}

- (void)changeColor4
{
    NSLog(@"changeColor4");
    SXModel *model=[SXModel shareModel];
    if (model.sebanIndex==15) {
        model.sebanIndex=1;
    } else
        model.sebanIndex++;
    NSMutableDictionary *mutableDic2 = [self dataFromDBToColor:model.sebanIndex];
    if (mutableDic2 && [mutableDic2 count]>0) {
        model.parentNo=[NSString stringWithFormat:@"%d",model.sebanIndex];
        [self.filterLevel4CV reloadData];
        //[self.scroll4CVView addSubview:self.filterLevel4CAno];
    }
    //[self performSelector:@selector(changeColor3) withObject:nil afterDelay:0];
    //[self performSelectorOnMainThread:@selector(changeColor3) withObject:nil waitUntilDone:NO];
}

- (void)changeColor3
{
    NSLog(@"changeColor3");
    SXModel *model=[SXModel shareModel];
    
    NSMutableDictionary *mutableDic2 = [self dataFromDBToColor:model.anoIndex];
    if (mutableDic2 && [mutableDic2 count]>0) {
        model.parentNoA=[NSString stringWithFormat:@"%d",model.anoIndex];
        [self.filterLevel4CAno reloadData];
        //[self.scroll4CVView addSubview:self.filterLevel4CAno];
    }
    
    //[self changePage];
    
}

//- (void)changePage
//{
//    SXModel *model=[SXModel shareModel];
//    if (model.Arrow==2) {
//        [self.scroll4CVView setContentOffset:CGPointMake(0, 0) animated:NO];
//    } else if(model.Arrow==1)
//        [self.scroll4CVView setContentOffset:CGPointMake(270*2, 0) animated:NO];
//}



- (void)leftArrowAction
{
    NSLog(@"leftArrow");
    
    SXModel *model=[SXModel shareModel];
    
    //model.Arrow=1;
    
    if (model.sebanIndex==1) {
        model.sebanIndex=15;
        model.befIndex=14;
        model.anoIndex=16;
    } else {
        model.sebanIndex=model.sebanIndex-2;
        model.befIndex=model.sebanIndex-1;
        model.anoIndex=model.sebanIndex+1;
    }
    
    [self performSelector:@selector(changeColor1) withObject:nil];
    
}

- (void)rightArrowAction
{
    NSLog(@"rightArrow");
    //m_filterSubmenutype=EM_FST_Zhuseban;
    
    SXModel *model=[SXModel shareModel];
    
    //model.Arrow=2;
    
    if (model.sebanIndex==14) {
        model.befIndex=15;
        model.sebanIndex=16;
        model.anoIndex=1;
    } else if (model.sebanIndex==16){
        model.befIndex=1;
        model.sebanIndex=2;
        model.anoIndex=3;
    } else {
        model.sebanIndex=model.sebanIndex+2;
        model.befIndex=model.sebanIndex-1;
        model.anoIndex=model.sebanIndex+1;
    }
    
    NSLog(@"per=%d,now=%d,nex=%d",model.befIndex,model.sebanIndex,model.anoIndex);
    [self performSelectorOnMainThread:@selector(changeColor1) withObject:nil waitUntilDone:NO];
    
//    //1.获得全局的并发队列
//    dispatch_queue_t queue =  dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//    //dispatch_queue_t  queue= dispatch_queue_create("changeColor", NULL);
//    //2.添加任务到队列中，就可以执行任务
//    //异步函数：具备开启新线程的能力
//    dispatch_async(queue, ^{
//        NSLog(@"刷新1----%@",[NSThread currentThread]);
//        [self changeColor1];
//        });
//    dispatch_async(queue, ^{
//        NSLog(@"刷新2----%@",[NSThread currentThread]);
//        [self changeColor2];
//        });
//    dispatch_async(queue, ^{
//        NSLog(@"刷新2----%@",[NSThread currentThread]);
//        [self changeColor3];
//    });
//    //打印主线程
//    NSLog(@"主线程----%@",[NSThread mainThread]);
   
}

#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    SXModel *model=[SXModel shareModel];
    if (scrollView==self.collectionView) {
        model.scrolled=YES;
        
        if (!isFetchData) {
            
            float offset = 1.f-(1.f/(1.f+currentpage));
            
            if (self.collectionView.contentOffset.y > self.collectionView.contentSize.height*offset) {
                NSLog(@"  offset  ---- %f",offset);
                isNewSearch = NO;
                isFetchData = YES;
                isAddSearch = NO;
                
                if (isHomeSearch) {
                    [NSThread detachNewThreadSelector:@selector(footnetwork) toTarget:self withObject:nil];
                }
                else
                {
                    [NSThread detachNewThreadSelector:@selector(footnetworkWithSearch:) toTarget:self withObject:nil];
                }
            }
        }
    }

}

- (void)killScroll
{
    CGPoint offset = self.collectionView.contentOffset;
    offset.x -= 1.0;
    offset.y -= 1.0;
    [self.collectionView setContentOffset:offset animated:YES];
    offset.x += 1.0;
    offset.y += 1.0;
    [self.collectionView setContentOffset:offset animated:YES];
}
-(void)footnetworkWithSearch:(int)beixin
{
    NSArray *keyValue = [SearchDic allKeys];
    NSString *searchStr;
    NSMutableArray *lblArray = [[NSMutableArray alloc] init];
    if ([keyValue count]>0) {
        
        NSMutableDictionary *strClothesDic = [[NSMutableDictionary alloc] init];
        [strClothesDic setObject:@"" forKey:@"usesituation"];
        [strClothesDic setObject:@"female" forKey:@"gender"];
        [strClothesDic setObject:@"" forKey:@"wholestyle"];
        [strClothesDic setObject:@"" forKey:@"season"];
        
        for (int i = 0; i < [keyValue count]; i++) {
            NSMutableDictionary *clothesDic = [SearchDic objectForKey:[keyValue objectAtIndex:i]];
            NSMutableDictionary *lblClothesDic = [[NSMutableDictionary alloc] init];
            
            [lblClothesDic setObject:[clothesDic objectForKey:@"l1"] forKey:@"firstid"];
            [lblClothesDic setObject:[clothesDic objectForKey:@"l2"] forKey:@"secondid"];
            
            NSMutableDictionary *colorDicInfo = [clothesDic objectForKey:@"color"];
            NSMutableDictionary *colorDic = [[NSMutableDictionary alloc] init];
            NSString *colorType = (NSString*)[colorDicInfo objectForKey:@"colorType"];
            if ([colorType isEqualToString:@"youzhuse"]) {
                
                NSMutableDictionary *tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"zhuse"];
                NSArray *tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    NSMutableString *str = [[NSMutableString alloc] init];
                    [str appendString:(NSString*)[tmpArray objectAtIndex:0]];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            [str appendString:@","];
                            [str appendString:(NSString*)[tmpArray objectAtIndex:i]];
                        }
                    }
                    [colorDic setObject:@"1" forKey:@"type"];
                    [colorDic setObject:str forKey:@"color"];
                }
                else
                {
                    [colorDic setObject:@"" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color"];
                }
                
                tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"peise"];
                tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
//                    NSMutableString *str = [[NSMutableString alloc] init];
//                    [str appendString:(NSString*)[tmpArray objectAtIndex:0]];
//                    if ([tmpArray count]>1) {
//                        for (int i =1; i<[tmpArray count]; i++) {
//                            [str appendString:@","];
//                            [str appendString:(NSString*)[tmpArray objectAtIndex:i]];
//                        }
//                    }
//                    [colorDic setObject:str forKey:@"color1"];
//                    [colorDic setObject:@"1" forKey:@"type"];
                    
                    int value = 0;
                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
                    value = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                    //value = [(NSString*)[tmpArray objectAtIndex:0] intValue];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:i];
                            int tmpvalue = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                            value = tmpvalue|value;
                        }
                    }
                    [colorDic setObject:[NSString stringWithFormat:@"%d",value] forKey:@"color1"];
                    [colorDic setObject:@"1" forKey:@"type"];

                }
                else
                {
                    [colorDic setObject:@"" forKey:@"color1"];
                }
                
                tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"yanse"];
                tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    //ExtValue
//                    NSMutableString *str = [[NSMutableString alloc] init];
//                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
//                    [str appendString:(NSString*)[ysDic objectForKey:@"ValueID"]];
//                    if ([tmpArray count]>1) {
//                        for (int i =1; i<[tmpArray count]; i++) {
//                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
//                            [str appendString:@","];
//                            [str appendString:(NSString*)[ysDic objectForKey:@"ValueID"]];
//                        }
//                    }
//                    [colorDic setObject:str forKey:@"colorstyle"];

                    int value = 0;
                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
                    value = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:i];
                            int tmpvalue = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                            value = tmpvalue|value;
                        }
                    }

                    [colorDic setObject:[NSString stringWithFormat:@"%d",value] forKey:@"colorstyle"];
                    [colorDic setObject:@"1" forKey:@"type"];
                }
                else
                {
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                }
                
            }
            else if ([colorType isEqualToString:@"chunse"]){
                
                NSMutableDictionary *tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"chunse"];
                NSArray *tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    NSMutableString *str = [[NSMutableString alloc] init];
                    [str appendString:(NSString*)[tmpArray objectAtIndex:0]];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            [str appendString:@","];
                            [str appendString:(NSString*)[tmpArray objectAtIndex:i]];
                        }
                    }
                    [colorDic setObject:@"0" forKey:@"type"];
                    [colorDic setObject:str forKey:@"color"];
                    [colorDic setObject:@"" forKey:@"color1"];
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                }
                else
                {
                    [colorDic setObject:@"" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color"];
                    [colorDic setObject:@"" forKey:@"color1"];
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                    [colorDic setObject:@"" forKey:@"type"];
                }
                
            }
            else if ([colorType isEqualToString:@"wuzhuse"])
            {
                
                NSMutableDictionary *tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"zhuse"];
                NSArray *tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    int value = 0;
                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
                    value = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                    //value = [(NSString*)[tmpArray objectAtIndex:0] intValue];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:i];
                            int tmpvalue = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                            value = tmpvalue|value;
                        }
                    }
                    [colorDic setObject:[NSString stringWithFormat:@"%d",value] forKey:@"color"];
                    [colorDic setObject:@"2" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color1"];

                }
                else
                {
                    [colorDic setObject:@"" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color1"];
                    [colorDic setObject:@"" forKey:@"color"];
                }
                
                tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"yanse"];
                tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    
                    int value = 0;
                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
                    value = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:i];
                            int tmpvalue = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                            value = tmpvalue|value;
                        }
                    }
                    
                    [colorDic setObject:[NSString stringWithFormat:@"%d",value] forKey:@"colorstyle"];
                    [colorDic setObject:@"2" forKey:@"type"];
                }
                else
                {
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                }
                
            }
            else if ([colorType isEqualToString:@"touming"]){
                NSMutableDictionary *tmpdic = (NSMutableDictionary *)[colorDicInfo objectForKey:@"touming"];
                NSArray *tmpArray = [tmpdic allValues];
                if ([tmpArray count]>0) {
                    int value = 0;
                    NSMutableDictionary *ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:0];
                    value = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                    //value = [(NSString*)[tmpArray objectAtIndex:0] intValue];
                    if ([tmpArray count]>1) {
                        for (int i =1; i<[tmpArray count]; i++) {
                            ysDic = (NSMutableDictionary*)[tmpArray objectAtIndex:i];
                            int tmpvalue = [(NSString*)[ysDic objectForKey:@"ExtValue"] intValue];
                            value = tmpvalue|value;
                        }
                    }
                    [colorDic setObject:[NSString stringWithFormat:@"%d",value] forKey:@"color"];
                    [colorDic setObject:@"4" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color1"];
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                    
                }
                else
                {
                    [colorDic setObject:@"" forKey:@"type"];
                    [colorDic setObject:@"" forKey:@"color1"];
                    [colorDic setObject:@"" forKey:@"color"];
                    [colorDic setObject:@"" forKey:@"colorstyle"];
                }
            }
            else
            {
                [colorDic setObject:@"" forKey:@"type"];
                [colorDic setObject:@"" forKey:@"colorstyle"];
                [colorDic setObject:@"" forKey:@"color1"];
                [colorDic setObject:@"" forKey:@"color"];
            }
            
            [lblClothesDic setObject:colorDic forKey:@"colors"];
            
            NSMutableDictionary *xijieDic = [clothesDic objectForKey:@"xijie"];
            NSArray *tmpArray = [xijieDic allValues];
            NSMutableArray *xijieArray = [[NSMutableArray alloc] init];
            if (tmpArray && [tmpArray count]>0) {
                for (int i =0; i<[tmpArray count]; i++) {
                    NSMutableDictionary *dic = (NSMutableDictionary *)[tmpArray objectAtIndex:i];
                    if ([dic objectForKey:@"checkValue"]) {
                        NSMutableDictionary *valueDic = [[NSMutableDictionary alloc] init];
                        [valueDic setObject:[dic objectForKey:@"ID"] forKey:@"thirdid"];
                        NSMutableDictionary *checkDic = [dic objectForKey:@"checkValue"];
                        [valueDic setObject:[checkDic objectForKey:@"ID"] forKey:@"fourthid"];
                        [xijieArray addObject:valueDic];
                    }
                }
            }
            
            NSMutableDictionary *speDic = [[NSMutableDictionary alloc] init];
            [speDic setObject:@"" forKey:@"str_m"];
            [speDic setObject:@"" forKey:@"str_d"];
            [speDic setObject:@"" forKey:@"str_s"];
            
            
            [lblClothesDic setObject:xijieArray forKey:@"tf_labels"];
            [lblClothesDic setObject:speDic forKey:@"speciallabelsid"];
            [lblArray addObject:lblClothesDic];
        }
        

        [strClothesDic setObject:lblArray forKey:@"labels"];
        
        NSData *data = [NSJSONSerialization dataWithJSONObject:strClothesDic options:NSJSONWritingPrettyPrinted error:nil];
        NSLog(@"----------- %@",[[NSString alloc] initWithData:data encoding:4]);
        searchStr = [[NSString alloc] initWithData:data encoding:4];
    }
    
//    NSString *labelsStr =[NSString stringWithFormat:@"{\"usesituation\":\"\",\"gender\":\"female\",\"wholestyle\":\"\",\"season\":\"\",\"labels\":[{\"tf_labels\":[],\"colors\":{\"type\":\"\",\"colorstyle\":\"\",\"color1\":\"\",\"color\":\"\"},\"speciallabelsid\":{\"str_m\":\"\",\"str_d\":\"\",\"str_s\":\"\"},\"firstid\":\"%d\",\"secondid\":%@}]}",topOneType,topTwoValue];
//    NSLog(@"------------1 %@",labelsStr);
    int ncurrentpage;
    if (isNewSearch) {
        ncurrentpage = 1;
    } else if (isFetchData) {
        ncurrentpage = currentpage+1;
    } else {
        ncurrentpage = 1;
    }
    
    SXModel *model=[SXModel shareModel];
    if (ncurrentpage > totalpage) {
//        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"消息" message:@"已无数据显示" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alert show];
//        return;
        
        model.pageOver=YES;
    } else
        model.pageOver=NO;
    
    if (!model.pageOver) {
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                                 "<soap12:Envelope "
                                 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                                 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                                 "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                                 "<soap12:Body>"
                                 "<SearchPicList xmlns=\"http://tempuri.org/\">"
                                 "<userid>%@</userid>"
                                 "<userip>%@</userip>"
                                 "<address>%@</address>"
                                 "<date>%@</date>"
                                 "<labels>%@</labels>"
                                 "<type>%@</type>"
                                 "<optimizetype>%@</optimizetype>"
                                 "<currentpage>%d</currentpage>"
                                 "<pagesize>%@</pagesize>"
                                 "</SearchPicList>"
                                 "</soap12:Body>"
                                 "</soap12:Envelope>", [[NSUserDefaults standardUserDefaults]valueForKey:@"UserID"],@"",@"",@"",searchStr,@"2",@"",ncurrentpage,@"20"];
        CLog(@"shangzhuangsousuo!!!%@",soapMessage);//[NSString stringWithFormat:@"%d",currentpage+1]
        
        
        //请求发送到的路径
        //    NSString *url = [NSString stringWithFormat:@"%@WebService/Watu_WebService.asmx",API_SERVER_URL];
        NSString *soapActionURL = @"http://tempuri.org/SearchPicList";
        NetWebServiceRequest *request = [NetWebServiceRequest serviceRequestUrl:API_SERVER_URL SOAPActionURL:soapActionURL ServiceMethodName:@"getMobileCodeInfo" SoapMessage:soapMessage];
        [request startAsynchronous];
        [request setDelegate:self];
        self.runningRequest = request;
    }
    
    
}


#pragma mark NetWebServiceRequestDelegate Methods
- (void)netRequestStarted:(NetWebServiceRequest *)request
{
    CLog(@"Start");
    self.view.userInteractionEnabled = YES;
}


- (void)netRequestFinished:(NetWebServiceRequest *)request
      finishedInfoToResult:(NSString *)result
              responseData:(NSData *)requestData{
    CLog(@"%@",result);
    if (request == self.gettingRequest) {
        // 处理返回的数据
        //NSData *returnData = requestData;
        if (result) {
//            NSString *strReturn = result;
//            NSLog(@"%@",strReturn);
//            NSLog(@"%ld",(long)[response statusCode]);
            
            //NSData *data = [returnData dataUsingEncoding:NSUTF8StringEncoding];
            NSData *data = [result dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
           // NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];
            NSString *imgUrl = (NSString *)[jsonObj objectForKey:@"ImageUrl"];
            NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!json%@",jsonObj);
            NSMutableArray *homeColors = (NSMutableArray *)[jsonObj objectForKey:@"HomeColors"];
            [userDefaults setObject:imgUrl forKey:@"ImageUrl"];
            [userDefaults setObject:homeColors forKey:@"HomeColors"];
            SXModel *model=[SXModel shareModel];
            model.colorArr=[NSMutableArray arrayWithArray:[userDefaults valueForKey:@"HomeColors"]];
            
            [self footnetwork];
        }
        
    }
    else if (request == self.runningRequest)
    {
        [self hiddenLoadingView];
        //[self clockSelectBtn];
        NSData *data = [result dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"runningJson=%@",[jsonObj objectForKey:@"data"]);
        NSMutableDictionary *dataDic = [jsonObj objectForKey:@"data"];
        if ([(NSString*)[jsonObj objectForKey:@"status"] isEqualToString:@"1"]) {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"结果" message:[jsonObj objectForKey:@"msg"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            return;
        }
        else if ([(NSString*)[jsonObj objectForKey:@"status"] isEqualToString:@"2"]) {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"结果" message:[jsonObj objectForKey:@"msg"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            return;
        }
        else if([(NSString*)[jsonObj objectForKey:@"status"] isEqualToString:@"0"])
        {
            SXModel *model=[SXModel shareModel];
            if (isNewSearch||isAddSearch) {
                [model.infoArr removeAllObjects];
            }
            
            totalNum = [[dataDic objectForKey:@"totalnum"] intValue];
            totalpage = [[dataDic objectForKey:@"totalpage"] intValue];
            currentpage = [[dataDic objectForKey:@"currentpage"] intValue];
            //int iCount = [model.infoArr count];
            NSMutableArray *countArr = [[jsonObj objectForKey:@"data"] objectForKey:@"info"];
//            if (countArr.count<5) {
//                for (int i=0; i<4; i++) {
//                    //NSString *AvgColor = @"#838D8E";
//                    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:600],@"Height",@"kidding",@"Name",[NSNumber numberWithInteger:500],@"Width",@"#838D8E",@"AvgColor",nil];
//                    [countArr addObject:dic];
//                }
//            }
            //[model.infoArr addObjectsFromArray:[[jsonObj objectForKey:@"data"] objectForKey:@"info"]];
            NSLog(@"!!totalNum=%d,!!totalpage=%d,!!currentPage=%d",totalNum,totalpage,currentpage);
            
            //
//            SXModel *model=[SXModel shareModel];
//            BOOL defaultCellImg=NO;
//            if (model.imgInfo) {
//                for (ContentCollectionViewCell *cell in [self.collectionView visibleCells]) {
//                    NSDictionary *infodic = [model.infoArr objectAtIndex:[self.collectionView indexPathForCell:cell].row];
//                    NSString *strColor = [infodic objectForKey:@"AvgColor"];
//                    UIImage *defaulImg = [self imageWithColor:[self colorWithHexString:strColor]];
//                    
//                    if (cell.imageView.image==defaulImg) {
//                        defaultCellImg=YES;
//                        break;
//                    }
//                }
//            }
            
            
            
            if (isNewSearch || isAddSearch) {
                SXModel *model=[SXModel shareModel];
                NSLog(@"首次刷!!!%d,%d",model.colorIndex,model.customIndex);
                [model.infoArr addObjectsFromArray:[[jsonObj objectForKey:@"data"] objectForKey:@"info"]];
                NSLog(@"infoarrcount=%lu",(unsigned long)model.infoArr.count);
                [self.collectionView scrollsToTop];
                [self.collectionView setContentOffset:
                 CGPointMake(0, -self.collectionView.contentInset.top) animated:YES];
                [self.collectionView reloadData];
                //            CGPoint position = CGPointMake(320, 0.f);
                //            [self.collectionView setContentOffset:position];
                //isFetchData = YES;
                isFetchData=NO;
                model.refreshData=YES;
                //
                
            }
            else
            {
                NSLog(@"超过二十了！！！");
                
                //[self.collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:model.infoArr.count-1 inSection:0], nil]];
                
                NSMutableArray *countArr1 = [[NSMutableArray alloc] init];
                if ([countArr count]>0) {
                    for (int i = 0; i < [countArr count]; i++) {
                        
                        [model.infoArr addObject:[countArr objectAtIndex:i]];
                        [countArr1 addObject:[NSIndexPath indexPathForRow:[model.infoArr count]-1 inSection:0]];
                    }
                    //NSLog(@"################ %d  %d  %d",[countArr count],[countArr1 count],[model.infoArr count]);
                    //[self killScroll];
                    //[self.collectionView setScrollEnabled:NO];
//                    [self.collectionView performBatchUpdates:^{
//                        [self.collectionView insertItemsAtIndexPaths:countArr1];
//                    } completion:^(BOOL finished) {
//                        isFetchData = NO;
//                        [self.collectionView setScrollEnabled:YES];
//                    } ];
                    
                    
                    [self performSelector:@selector(collectionViewRefresh:) withObject:countArr1 afterDelay:0.5];
                    
                    //[self.collectionView insertItemsAtIndexPaths:countArr1];
                }
            }
            
            
        }
        
//        if (!isHomeSearch) {
//            filerBtn.alpha = 1.f;
//        }
    }
    
}
- (void)netRequestFailed:(NetWebServiceRequest *)request didRequestError:(NSError *)error{
    CLog(@"%@",error);
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"消息" message:@"网络连接异常" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];

    
}

#pragma mark - Actions

- (IBAction)searchAction:(id)sender {
    
////    NSMutableArray *arr = [userDefaults objectForKey:@"SearchArr"];
//    isHomeSearch = NO;
//    isNewSearch = YES;
//    topOneType = EM_TOT_NONE;
//    menuTopType = EM_MTT_top1;
//    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuView" owner:self options:nil];
//    MenuView * menuView = [nib objectAtIndex:0];//UIBlurEffectStyleDark
//    UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
//    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//    visualEffectView.frame = menuView.tv.frame;
//
////    [menuView.tv setBackgroundView:visualEffectView];
//    [menuView  addSubview:visualEffectView];
//    [menuView sendSubviewToBack:visualEffectView];
//    visualEffectView.layer.masksToBounds = YES;
//    visualEffectView.layer.cornerRadius = DefaultCornerRadius;
//    menuView.tv.layer.masksToBounds = YES;
//    menuView.tv.layer.cornerRadius = DefaultCornerRadius;
//    menuView.tv.delegate = self;
//    menuView.tv.dataSource = self;
//    menuView.tag = 12;
//    [self.view addSubview:menuView];
//    [menuView.tv reloadData];
    SXModel *model=[SXModel shareModel];
    if (!model.searched) {
        isHomeSearch = NO;
        isNewSearch = YES;
        topOneType = EM_TOT_NONE;
        menuTopType = EM_MTT_top1;
        //[self showTop1View];
//        if (self.iPhone) {
//            //[Utility showHelpWith:@"help2-4s@2x.png"];
//        } else
//            //[Utility showHelpWith:@"help2.png"];
    } else {
        //[self filterAction:nil];
    }
    
}

- (IBAction)dismissViewAction:(id)sender
{
    [UIView animateWithDuration:0.3 animations:^{
        [self.view viewWithTag:11].alpha=0;
        ((Type02 *)[self.view viewWithTag:11]).bgView.frame=CGRectMake(0, self.view.bounds.size.height, ((Type02 *)[self.view viewWithTag:11]).bgView.frame.size.width, ((Type02 *)[self.view viewWithTag:11]).bgView.frame.size.height);
    } completion:^(BOOL finished) {
        [[self.view viewWithTag:11] removeFromSuperview];
    }];
}

-(IBAction)leftBtnAction:(id)sender
{
    if (isLeftBtnHistory) {
        [self backToHome];
//        isHomeSearch = NO;
//        isNewSearch = YES;
//        topOneType = EM_TOT_NONE;
//        menuTopType = EM_MTT_top1;
//        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuView" owner:self options:nil];
//        MenuView * menuView = [nib objectAtIndex:0];//UIBlurEffectStyleDark
//        UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
//        UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//        visualEffectView.frame = menuView.tv.frame;
//        menuView.menuDelegate = self;
//        
//        //    [menuView.tv setBackgroundView:visualEffectView];
//        [menuView  addSubview:visualEffectView];
//        [menuView sendSubviewToBack:visualEffectView];
//        visualEffectView.layer.masksToBounds = YES;
//        visualEffectView.layer.cornerRadius = DefaultCornerRadius;
//        menuView.tv.layer.masksToBounds = YES;
//        menuView.tv.layer.cornerRadius = DefaultCornerRadius;
//        menuView.tv.delegate = self;
//        menuView.tv.dataSource = self;
//        menuView.tag = 12;
//        [self.view addSubview:menuView];
//        [menuView.tv reloadData];
//        
//        self.leftBtn.enabled = NO;
//        self.rightBtn.enabled = NO;
    }
    else
    {
        SXModel *model=[SXModel shareModel];
        model.addClothes=NO;
        model.createKuanshi=NO;
        model.createPeise=NO;
        model.createTuan=NO;
        model.tuanAction=NO;
        model.peiseAction=NO;
        model.sebanIndex=0;
        model.befIndex=0;
        model.anoIndex=0;
        
        [[self.navigationController.navigationBar viewWithTag:900] removeFromSuperview];
        
        viewType = EM_VT_Home;
        [UIView animateWithDuration:0.4 animations:^{
            filerDetailView.alpha=0;
            //filerDetailView.frame=CGRectMake(self.view.frame.size.width, filerDetailView.frame.origin.y, CGRectGetWidth(filerDetailView.frame), CGRectGetHeight(filerDetailView.frame));
        } completion:^(BOOL finished) {
            [filerDetailView removeFromSuperview];
        }];
        
//        SXModel *model=[SXModel shareModel];
//        model.juBuPeiSe=YES;
        
        self.leftBtn.hidden = YES;
        //self.leftBtn.userInteractionEnabled=NO;
        [self.leftBtn setImage:nil forState:UIControlStateNormal];
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(5, 0, 50, 30)];
        label.text=@"首页";
        label.tag=200;
        label.textAlignment=NSTextAlignmentCenter;
        label.font=[UIFont boldSystemFontOfSize:17];
        label.textColor=[self colorWithHexString:@"#9E59E4"];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftBtnAction:)]];
        self.leftBtn.hidden=NO;
        self.leftBtn.userInteractionEnabled=YES;
        [self.leftBtn addSubview:label];
        
        isLeftBtnHistory = YES;
//        UIImage *imageLeft=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"home_history_icon" ofType:@"png"]];
//        [self.leftBtn setImage:imageLeft forState:UIControlStateNormal];
        //filerDetailView = nil;
        [[self.rightBtn viewWithTag:100] removeFromSuperview];
        //[self.rightBtn setImage:[UIImage imageNamed:@"home_find.png"] forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"newFilter@2x.png"] forState:UIControlStateNormal];
    }

}
-(void)menuWillDismiss
{
    self.leftBtn.hidden=YES;
    self.leftBtn.enabled = YES;
    self.rightBtn.enabled = YES;
}
-(IBAction)rightBtnAction:(id)sender
{
    SXModel *model=[SXModel shareModel];
    if (!model.clockSetOpen) {
        model.chaKan=NO;
        model.changeClock=NO;
        model.timeIndex=0;
        model.hourIndex=605;
        model.minuteIndex=1500;
    
        [self.rightBtn setImage:nil forState:UIControlStateNormal];
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(25, 10, 50, 30)];
        label.text=@"返回";
        label.tag=777;
        label.textAlignment=NSTextAlignmentCenter;
        label.font=[UIFont boldSystemFontOfSize:17];
        label.textColor=[self colorWithHexString:@"#9E59E4"];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightBtnAction:)]];
        [self.rightBtn addSubview:label];
        
        ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"闹钟设定";
        
        [[self.view viewWithTag:888] removeFromSuperview];
        model.weekArr=[[NSMutableArray alloc] init];
        model.weekIndexArr=[[NSMutableArray alloc] init];
        [model.weekArr removeAllObjects];
        [model.weekIndexArr removeAllObjects];
        self.segIndex=0;
        self.sleep=NO;
        [self clockSettings];
        [UIView animateWithDuration:0.3 animations:^{
            [self.view viewWithTag:888].frame=self.view.bounds;
        }];
        [self.datePicker selectRow:model.timeIndex inComponent:0 animated:NO];
        [self.datePicker selectRow:model.hourIndex inComponent:1 animated:NO];
        [self.datePicker selectRow:model.minuteIndex inComponent:2 animated:NO];
        //_seg.selectedSegmentIndex=3;
//        [model.weekArr removeAllObjects];
//        [model.weekIndexArr removeAllObjects];
        
        //_seg.selectedSegmentIndex=self.segIndex;
        //[self controlPressed:_seg];
        model.clockSetOpen=YES;
        
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            [self.view viewWithTag:888].frame=CGRectMake(0, -self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
        }];
        model.clockSetOpen=NO;
        model.chaKan=NO;
        model.changeClock=NO;
        
        model.timeIndex=0;
        model.hourIndex=605;
        model.minuteIndex=1500;
        
        [[self.rightBtn viewWithTag:777] removeFromSuperview];
        [self.rightBtn setImage:[UIImage imageNamed:@"home_add@2x.png"] forState:UIControlStateNormal];
        ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"挖兔闹钟";
    }
    
}
#pragma mark - View methods
-(void)showTop1View
{
    
    [[self.view viewWithTag:12] removeFromSuperview];
    Type02 *tmpCustomView = (Type02*)[self.view viewWithTag:11];
    //NSLog(@"weizhi%f,%f,%f,%f",tmpCustomView.frame.origin.x,tmpCustomView.frame.origin.y,tmpCustomView.frame.size.width,CGRectGetHeight(tmpCustomView.frame));
    if (!tmpCustomView){
        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"Type02" owner:self options:nil];
        Type02 *tmpCustomView = [nib objectAtIndex:0];
        
        if ([self IsLessThanIphone5]) {
            tmpCustomView.frame = CGRectMake(0, -88, tmpCustomView.frame.size.width, tmpCustomView.frame.size.height);
        }
        tmpCustomView.tag = 11;
        tmpCustomView.alpha=0;
        //tmpCustomView.titleBG.hidden = YES;
        tmpCustomView.titleBG.hidden = NO;
        tmpCustomView.titleLbl.text = @"一类选择";
        tmpCustomView.titleLbl.hidden = NO;
        //tmpCustomView.titleBG.frame=CGRectMake(0, tmpCustomView.titleBG.frame.origin.y, [self screenSize].width, CGRectGetHeight(tmpCustomView.titleBG.frame));
        tmpCustomView.frame=CGRectMake(0, tmpCustomView.frame.origin.y, CGRectGetWidth(tmpCustomView.frame), CGRectGetHeight(tmpCustomView.frame));
        //NSLog(@"--------------------screen size %f",[self screenSize].width);
        
        //[tmpCustomView.backBtn addTarget:self action:@selector(BackToMenuLevel1:) forControlEvents:UIControlEventTouchUpInside];
        //self.level2CV.frame=CGRectMake(self.level2CV.frame.origin.x, self.level2CV.frame.origin.y-10, CGRectGetWidth(self.level2CV.frame), CGRectGetHeight(self.level2CV.frame));
//        SXModel *model=[SXModel shareModel];
//        if (model.level2CV) {
//            self.level2CV.frame=CGRectMake(self.level2CV.frame.origin.x, self.level2CV.frame.origin.y+5, CGRectGetWidth(self.level2CV.frame), CGRectGetHeight(self.level2CV.frame));
//        }
        
        [tmpCustomView.bgView addSubview:self.level2CV];
        
        
        [UIView animateWithDuration:0.3 animations:^{
            tmpCustomView.alpha=1;
            tmpCustomView.bgView.frame=CGRectMake(0, 50, CGRectGetWidth(tmpCustomView.bgView.frame), CGRectGetHeight(tmpCustomView.bgView.frame));
        }];
        
        
        [self.view addSubview:tmpCustomView];
    
    }
    menuTopType = EM_MTT_top1;
    tmpCustomView.titleBG.hidden = NO;
    tmpCustomView.titleLbl.text = @"一类选择";
    tmpCustomView.titleLbl.hidden = NO;
    self.level2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"glass.png",@"hat.png",@"scraf.png",@"skirt.png",@"tops3.png",
                               @"pants.png",@"tops1.png",@"tops2.png",@"shoes.png",
                               @"socks.png",@"bags.png",@"jumpsuits.png",nil];
    [UIView animateWithDuration:0.6 animations:^{
        [self.level2CV reloadData];
    }];
}

#pragma mark - Top One Actions
- (IBAction)ToponeBtnClick:(id)sender {
    NSLog(@"top one  action!");
}

#pragma mark - UITableView Delegate
- (void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //return [self.level3CVinfoArrays count];
    if (tableView==self.clockTableView1) {
        return 2;
    } else if (tableView==self.clockTableView2) {
        return 2;
        
    } else if (tableView==self.clockSettingTable){
        return self.weekSArr.count;
        
    } else if (tableView == self.clockTable) {
        SXModel *model=[SXModel shareModel];
        return model.alarmArr.count;
        
    } else {
        NSMutableArray *arr = [userDefaults objectForKey:@"SearchArr"];
        return [arr count];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.clockSettingTable==tableView) {
        return 40;
    } else if (self.clockTable==tableView){
        return 60;
    } else if (self.clockTableView1==tableView){
        return 30;
    } else if (self.clockTableView2==tableView){
        return 60;
    } else
        return 50;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.clockTable) {
        SXModel *model=[SXModel shareModel];
        NSString *cellStr=@"cellStr0";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStr];
        if (!cell) {
            cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr];
            UISwitch *swith = [[UISwitch alloc] initWithFrame:CGRectMake(cell.frame.size.width-65, cell.frame.size.height/2-5, 60, 40)];
            [swith addTarget:self action:@selector(onOrOff:) forControlEvents:UIControlEventValueChanged];
            //默认状态为打开
            swith.tag=999+indexPath.row;
            swith.on = YES;
            [cell addSubview:swith];
        }
        cell.textLabel.text=[NSString stringWithFormat:@"%@",[[model.alarmArr objectAtIndex:indexPath.row] valueForKey:@"TIME"]];
        cell.textLabel.textColor=[self colorWithHexString:@"#9E59E4"];
        cell.detailTextLabel.text=[[model.alarmArr objectAtIndex:indexPath.row] valueForKey:@"WEEK"];
        cell.detailTextLabel.textColor=[UIColor blackColor];
        cell.detailTextLabel.font=[UIFont boldSystemFontOfSize:11];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        NSLog(@"222333");
        if (((NSMutableArray *)[[model.localNotiArr objectAtIndex:indexPath.row] objectAtIndex:0]).count>0) {
            BOOL onoff=[[[[model.localNotiArr objectAtIndex:indexPath.row] objectAtIndex:0] valueForKey:@"ONOFF"] boolValue];
            if (onoff) {
                ((UISwitch *)[cell viewWithTag:999+indexPath.row]).on=YES;
                cell.textLabel.textColor=[self colorWithHexString:@"#9E59E4"];
                cell.detailTextLabel.textColor=[UIColor blackColor];
            } else {
                ((UISwitch *)[cell viewWithTag:999+indexPath.row]).on=NO;
                cell.textLabel.textColor=[UIColor grayColor];
                cell.detailTextLabel.textColor=[UIColor grayColor];
            }
            
        }
        
        
        return cell;
    }
    if (tableView==self.clockTableView1) {
        NSString *cellStr1=@"cellStr1";
        NSString *cellStr2=@"cellStr2";
        UITableViewCell *cell=[[UITableViewCell alloc] init];
        UITableViewCell *cell1=[tableView dequeueReusableCellWithIdentifier:cellStr1];
        UITableViewCell *cell2=[tableView dequeueReusableCellWithIdentifier:cellStr2];
        if (!cell1) {
            cell1=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellStr1];
//            _seg=[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"不重复",@"每天",@"工作日", @"周末"/*,@"手选"*/,nil]];
//            [_seg setTintColor:[self colorWithHexString:@"#9E59E4"]];
//            _seg.frame=CGRectMake(cell1.frame.size.width-200-5, 2, 200, cell1.frame.size.height-4);
//            _seg.selectedSegmentIndex=self.segIndex;
//            [_seg addTarget:self action:@selector(controlPressed:) forControlEvents:UIControlEventValueChanged];
//            _seg.tag=400;
//            [cell1 addSubview:_seg];
            
            self.buttonArr=[[NSMutableArray alloc] init];
            for (int i=0; i<4; i++) {
                switch (i) {
                    case 0:{
                        _cellBtn1=[[UILabel alloc] init];
                        //[_cellBtn1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)]];
                        _cellBtn1.tag=500;
                        _cellBtn1.frame=CGRectMake(cell1.frame.size.width-(20+50*4)+(50+5)*i, cell1.frame.size.height/2-20-7, 50, 40);
                        
                        _cellBtn1.text=@"不重复";
                        _cellBtn1.font=[UIFont boldSystemFontOfSize:13];
                        //[_cellBtn1 setBackgroundColor:[UIColor blueColor]];
                        _cellBtn1.textAlignment=NSTextAlignmentCenter;
                        _cellBtn1.textColor=[UIColor grayColor];
                        _cellBtn1.userInteractionEnabled=YES;
                        
                        
                        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                        [btn addTarget:self action:@selector(selectMethod:) forControlEvents:UIControlEventTouchUpInside];
                        btn.frame=_cellBtn1.bounds;
                        btn.tag=i+600;
                        [_cellBtn1 addSubview:btn];
                        
                        [cell1 addSubview:_cellBtn1];
                        
                        //[self.buttonArr addObject:_cellBtn1];
                    }
                        
                        break;
                    case 1:{
                        _cellBtn2=[[UILabel alloc] init];
                        //[_cellBtn2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)]];
                        _cellBtn2.tag=501;
                        _cellBtn2.frame=CGRectMake(cell1.frame.size.width-(20+50*4)+(50+5)*i, cell1.frame.size.height/2-20-7, 50, 40);
                        
                        _cellBtn2.text=@"每天";
                        _cellBtn2.textAlignment=NSTextAlignmentCenter;
                        _cellBtn2.font=[UIFont boldSystemFontOfSize:13];
                        [_cellBtn2 setBackgroundColor:[UIColor clearColor]];
                        _cellBtn2.textColor=[UIColor grayColor];
                        _cellBtn2.userInteractionEnabled=YES;
                        
                        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                        [btn addTarget:self action:@selector(selectMethod:) forControlEvents:UIControlEventTouchUpInside];
                        btn.frame=_cellBtn2.bounds;
                        btn.tag=i+600;
                        [_cellBtn2 addSubview:btn];
                        
                        [cell1 addSubview:_cellBtn2];
                        //[self.buttonArr addObject:_cellBtn1];
                    }
                        
                        break;
                    case 2:{
                        _cellBtn3=[[UILabel alloc] init];
                        //[_cellBtn3 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)]];
                        _cellBtn3.tag=502;
                        _cellBtn3.frame=CGRectMake(cell1.frame.size.width-(20+50*4)+(50+5)*i, cell1.frame.size.height/2-20-7, 50, 40);
                        
                        _cellBtn3.text=@"工作日";
                        _cellBtn3.textAlignment=NSTextAlignmentCenter;
                        _cellBtn3.font=[UIFont boldSystemFontOfSize:13];
                        [_cellBtn3 setBackgroundColor:[UIColor clearColor]];
                        _cellBtn3.textColor=[UIColor grayColor];
                        _cellBtn3.userInteractionEnabled=YES;
                        
                        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                        [btn addTarget:self action:@selector(selectMethod:) forControlEvents:UIControlEventTouchUpInside];
                        btn.frame=_cellBtn3.bounds;
                        btn.tag=i+600;
                        [_cellBtn3 addSubview:btn];
                        
                        [cell1 addSubview:_cellBtn3];
                        //[self.buttonArr addObject:_cellBtn1];
                    }
                
                        break;
                    case 3:{
                        _cellBtn4=[[UILabel alloc] init];
                        //[_cellBtn4 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)]];
                        _cellBtn4.tag=503;
                        _cellBtn4.frame=CGRectMake(cell1.frame.size.width-(20+50*4)+(50+5)*i, cell1.frame.size.height/2-20-7, 50, 40);
                        
                        _cellBtn4.text=@"周末";
                        _cellBtn4.textAlignment=NSTextAlignmentCenter;
                        _cellBtn4.font=[UIFont boldSystemFontOfSize:13];
                        [_cellBtn4 setBackgroundColor:[UIColor clearColor]];
                        _cellBtn4.textColor=[UIColor grayColor];
                        _cellBtn4.userInteractionEnabled=YES;
                        
                        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                        [btn addTarget:self action:@selector(selectMethod:) forControlEvents:UIControlEventTouchUpInside];
                        btn.frame=_cellBtn4.bounds;
                        btn.tag=i+600;
                        [_cellBtn4 addSubview:btn];
                        
                        [cell1 addSubview:_cellBtn4];
                        //[self.buttonArr addObject:_cellBtn1];
                    }
                        
                        break;
                    
                    default:
                        break;
                }
                
            }
            
            
            cell1.textLabel.text=@"重复";
            cell1.selectionStyle=UITableViewCellSelectionStyleNone;
            //cell1.backgroundColor=[UIColor greenColor];
            
            cell=cell1;
        }
        
        if (!cell2) {
            cell2=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr2];
            for (int i=0; i<7; i++) {
                UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
                [button addTarget:self action:@selector(selectWeek:) forControlEvents:UIControlEventTouchUpInside];
                button.tag=i+300;
                button.frame=CGRectMake(cell2.frame.size.width/2-(48+35*7)/2+(35+8)*i, cell2.frame.size.height/2-15-9, 35, 30);
                switch (i) {
                    case 0:
                        [button setTitle:@"星期一" forState:UIControlStateNormal];
                        break;
                    case 1:
                        [button setTitle:@"星期二" forState:UIControlStateNormal];
                        break;
                    case 2:
                        [button setTitle:@"星期三" forState:UIControlStateNormal];
                        break;
                    case 3:
                        [button setTitle:@"星期四" forState:UIControlStateNormal];
                        break;
                    case 4:
                        [button setTitle:@"星期五" forState:UIControlStateNormal];
                        break;
                    case 5:
                        [button setTitle:@"星期六" forState:UIControlStateNormal];
                        break;
                    case 6:
                        [button setTitle:@"星期日" forState:UIControlStateNormal];
                        break;
                        
                    default:
                        break;
                }
                button.titleLabel.font=[UIFont boldSystemFontOfSize:11];
                //[button setBackgroundColor:[UIColor redColor]];
                [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                cell2.selectionStyle=UITableViewCellSelectionStyleNone;
                //cell2.backgroundColor=[UIColor purpleColor];
                [cell2 addSubview:button];
            }
            
            cell=cell2;
        }
        
        
        if (indexPath.row==0) {
            if (self.segIndex<=3) {
                for (int i=0; i<4; i++) {
                    UILabel *label=(UILabel *)[cell1 viewWithTag:500+i];
                    if (i==self.segIndex) {
                        label.textColor=[self colorWithHexString:@"#9E59E4"];
                    } else
                        label.textColor=[UIColor grayColor];
                }
        
            } else if(self.segIndex==5) {
                for (int i=0; i<4; i++) {
                    UILabel *label=(UILabel *)[cell1 viewWithTag:500+i];
                    label.textColor=[UIColor grayColor];
                }
            }
            
            cell=cell1;
        }
        if (indexPath.row==1){
            SXModel *model=[SXModel shareModel];
            if (model.weekArr.count>0) {
                for (int j=0; j<7; j++) {
                    UIButton *button=(UIButton *)[cell2 viewWithTag:j+300];
                    int dif=0;
                    for (NSString *str in model.weekArr) {
                        dif++;
                        if ([str isEqualToString:button.titleLabel.text]) {
                            [button setTitleColor:[self colorWithHexString:@"#9E59E4"] forState:UIControlStateNormal];
                            break;
                        }
                        if (dif==model.weekArr.count) {
                            [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                        }
                    }
                }
            }
            
            cell=cell2;
        }
        
        
//        NSString *weekText=[[NSString alloc] init];
//        SXModel *model=[SXModel shareModel];
//        for (NSString *str in model.weekArr) {
//            weekText=[weekText stringByAppendingString:[NSString stringWithFormat:@"%@ ",[str substringFromIndex:2]]];
//        }
//        cell.detailTextLabel.text=weekText;
        
        
        return cell;
        
    } else if (tableView==self.clockTableView2) {
        NSString *cellStr=@"cellStr2";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStr];
        if (!cell) {
            cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellStr];
            if (indexPath.row==0) {
                UISwitch *swith = [[UISwitch alloc] initWithFrame:CGRectMake(cell.frame.size.width-65, cell.frame.size.height/2-7, 60, 40)];
                [swith addTarget:self action:@selector(sleepAWhile:) forControlEvents:UIControlEventValueChanged];
                //默认状态为关闭
                //swith.tag=999+indexPath.row;
                swith.on = self.sleep;
                [cell addSubview:swith];
            }
        }
        cell.textLabel.text=[self.weekArr objectAtIndex:indexPath.row];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        //cell.backgroundColor=[UIColor greenColor];
        
        return cell;
        
    } else if (tableView==self.clockSettingTable) {
        NSString *cellStr=@"cellStr3";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStr];
        if (!cell) {
            cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellStr];
        }
        cell.textLabel.text=[self.weekSArr objectAtIndex:indexPath.row];
        cell.textLabel.font=[UIFont boldSystemFontOfSize:15];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        SXModel *model=[SXModel shareModel];
        NSLog(@"cellForRow: weekArr=%@",model.weekArr);
        int sum=0;
        if (model.weekArr.count>0) {
            for (NSString *str in model.weekArr) {
                if ([str isEqualToString:cell.textLabel.text]) {
                    NSLog(@"cellForRow: %@",cell.textLabel.text);
                    cell.accessoryType=UITableViewCellAccessoryCheckmark;
                    if ([cell.textLabel.text isEqualToString:@"星期一"]) {
                        sum++;
                    }
                    if ([cell.textLabel.text isEqualToString:@"星期日"]) {
                        sum=sum+2;
                    }
                }
                
            }
            
            if (sum==2) {
                NSArray *cellArr=[tableView visibleCells];
                UITableViewCell *cell0=[cellArr objectAtIndex:0];
                cell0.accessoryType=UITableViewCellAccessoryNone;
            }
            
            
        } else if (model.weekArr.count==0){
            cell.accessoryType=UITableViewCellAccessoryNone;
        }
        
        
        
        return cell;
        
    } else
    {
        static NSString * cellIndf = @"level3Info";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndf];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndf];
        }
//        if (indexPath.row == 0) {
//            cell.textLabel.text = @"新建搜索";
//            [cell.imageView setImage:[UIImage imageNamed:@"home_add.png"]];
//        }
//        else
//        {
            NSMutableString *str = [[NSMutableString alloc] init];
            NSMutableArray *arr = [userDefaults objectForKey:@"SearchArr"];
            NSMutableDictionary *dic = [arr objectAtIndex:indexPath.row];
            if ([[dic allKeys] count]<2) {
                NSMutableDictionary * clotheDic = [[dic allValues] objectAtIndex:0];
                NSMutableDictionary*l2keyDic = [clotheDic objectForKey:@"l2key"];
                [str appendString:[l2keyDic objectForKey:@"Name"]];
            }
            else if([[dic allKeys] count]>1)
            {
                NSMutableDictionary * clotheDic = [[dic allValues] objectAtIndex:0];
                NSMutableDictionary*l2keyDic = [clotheDic objectForKey:@"l2key"];
                [str appendString:[l2keyDic objectForKey:@"Name"]];
                [str appendString:@" "];
                for (int i = 1; i<[[dic allKeys] count]; i++) {
                    NSMutableDictionary * clotheDic = [[dic allValues] objectAtIndex:i];
                    NSMutableDictionary*l2keyDic = [clotheDic objectForKey:@"l2key"];
                    [str appendString:[l2keyDic objectForKey:@"Name"]];
                }
            }
            cell.textLabel.text = str;
        UIImage *imageCell=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"home_history" ofType:@"png"]];
            [cell.imageView setImage:imageCell];
//        }
        cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.backgroundColor = [UIColor clearColor];
        return cell;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MenuView *tmpmv = (MenuView *)[self.view viewWithTag:12];
    if ([tableView isKindOfClass:[tmpmv.tv class]]) {
//        if (indexPath.row == 0) {
//            isNewSearch = YES;
//            [self showTop1View];
//        }
//        else
//        {
            isNewSearch = YES;
            NSMutableArray *arr = [userDefaults objectForKey:@"SearchArr"];
            NSMutableDictionary *dic = [arr objectAtIndex:indexPath.row];
            [self saveSearchDic];
            SearchDic = dic;
            [self footnetworkWithSearch:0];
            [[self.view viewWithTag:12] removeFromSuperview];
        self.leftBtn.hidden=YES;
        self.leftBtn.enabled = YES;
        self.rightBtn.enabled = YES;
//        }
    } else if (self.clockTable==tableView){
        [[self.view viewWithTag:888] removeFromSuperview];
        SXModel *model=[SXModel shareModel];
        model.chaKan=YES;
        model.deleteIndex=(int)indexPath.row;
        NSLog(@"model.notiArr=%@",model.localNotiArr);
        NSString *alarmTime=[[model.alarmArr objectAtIndex:indexPath.row] valueForKey:@"TIME"];
        NSLog(@"alarmTime=%@",alarmTime);
        int hour=[[alarmTime substringWithRange:NSMakeRange(4, 2)] intValue];
        int minute=[[alarmTime substringFromIndex:7] intValue];
        int time=0;
        if ([[alarmTime substringToIndex:2] isEqualToString:@"上午"]) {
            time=0;
        } else {
            time=1;
            if (hour!=0) {
                hour=hour+12;
            }
            
        }
        //NSLog(@"time=%d,hour=%d,minute=%d",time,hour,minute);
        model.timeIndex=time;
        model.hourIndex=hour+600;
        model.minuteIndex=minute+1500;
        //NSLog(@"chakan=%d,%d,%d",(int)model.timeIndex,(int)model.hourIndex,(int)model.minuteIndex);
        
        model.weekArr=[model.alarmWeekArr objectAtIndex:indexPath.row];
        model.weekIndexArr=[model.alarmWeekIndexArr objectAtIndex:indexPath.row];
        //NSLog(@"chakan!!!=%@,%@,%@,%@",)
        self.segIndex=[[model.segIndexArr objectAtIndex:indexPath.row] intValue];
        NSLog(@"bseg=%d",self.segIndex);
        if ([model.weekArr containsObject:@"星期一"] && [model.weekArr containsObject:@"星期二"] &&[model.weekArr containsObject:@"星期三"] && [model.weekArr containsObject:@"星期四"] && [model.weekArr containsObject:@"星期五"] && [model.weekArr containsObject:@"星期六"] && [model.weekArr containsObject:@"星期日"]) {
            self.segIndex=1;
        } else if ([model.weekArr containsObject:@"星期一"] && [model.weekArr containsObject:@"星期二"] &&[model.weekArr containsObject:@"星期三"] && [model.weekArr containsObject:@"星期四"] && [model.weekArr containsObject:@"星期五"] && ![model.weekArr containsObject:@"星期六"] && ![model.weekArr containsObject:@"星期日"]) {
            self.segIndex=2;
        } else if (![model.weekArr containsObject:@"星期一"] && ![model.weekArr containsObject:@"星期二"] &&![model.weekArr containsObject:@"星期三"] && ![model.weekArr containsObject:@"星期四"] && ![model.weekArr containsObject:@"星期五"] && [model.weekArr containsObject:@"星期六"] && [model.weekArr containsObject:@"星期日"]) {
            self.segIndex=3;
        } else if (![model.weekArr containsObject:@"星期一"] && ![model.weekArr containsObject:@"星期二"] &&![model.weekArr containsObject:@"星期三"] && ![model.weekArr containsObject:@"星期四"] && ![model.weekArr containsObject:@"星期五"] && ![model.weekArr containsObject:@"星期六"] && ![model.weekArr containsObject:@"星期日"]) {
            self.segIndex=0;
        }
        NSLog(@"aseg=%d",self.segIndex);
        
        self.sleep=[[model.sleepMoreOpen objectAtIndex:indexPath.row] boolValue];
        
        [self.rightBtn setImage:nil forState:UIControlStateNormal];
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(25, 10, 50, 30)];
        label.text=@"返回";
        label.tag=777;
        label.textAlignment=NSTextAlignmentCenter;
        label.font=[UIFont boldSystemFontOfSize:17];
        label.textColor=[self colorWithHexString:@"#9E59E4"];
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightBtnAction:)]];
        [self.rightBtn addSubview:label];
        
        ((UILabel *)[self.navigationController.navigationBar viewWithTag:1000]).text=@"闹钟设定";
        
        [self clockSettings];
        [UIView animateWithDuration:0.3 animations:^{
            [self.view viewWithTag:888].frame=self.view.bounds;
        }];
        
        [self.datePicker selectRow:model.timeIndex inComponent:0 animated:NO];
        [self.datePicker selectRow:model.hourIndex inComponent:1 animated:NO];
        [self.datePicker selectRow:model.minuteIndex inComponent:2 animated:NO];
        
        if (model.openWeek) {
            [UIView animateWithDuration:0.2 animations:^{
                self.clockSettingTable.frame=CGRectMake(0, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), CGRectGetWidth(self.clockTableView1.frame), 0);
                self.clockSettingTable.alpha=0;
                self.clockTableView2.frame=CGRectMake(0, self.clockSettingTable.frame.origin.y, self.clockTableView2.frame.size.width, 34*2);
                [[self.view viewWithTag:888] viewWithTag:901].alpha=1;
                [[self.view viewWithTag:888] viewWithTag:902].alpha=1;
            }];
            
            model.openWeek=NO;
        }
    
        model.clockSetOpen=YES;
        
        //NSString *alarmWeek=[[model.alarmArr objectAtIndex:indexPath.row] valueForKey:@"WEEK"];
        
        //@"不重复",@"每天",@"工作日", @"周末",@"手选"
        
        
    } else if (self.clockTableView1==tableView){
        SXModel *model=[SXModel shareModel];
        if (!model.openWeek && _seg.selectedSegmentIndex==4) {
            CGRect frame=self.clockSettingTable.frame;
            self.clockSettingTable.alpha=0;
            [UIView animateWithDuration:0.2 animations:^{
                self.clockSettingTable.alpha=1;
                [self.clockSettingTable reloadData];
                self.clockSettingTable.frame=CGRectMake(0, frame.origin.y, frame.size.width, 50*7);
                self.clockTableView2.frame=CGRectMake(0, frame.origin.y+50*7, frame.size.width, 50*2);
                [[self.view viewWithTag:888] viewWithTag:901].alpha=0;
                [[self.view viewWithTag:888] viewWithTag:902].alpha=0;
            }];
            
            if (model.weekArr.count==7) {
                NSArray *cellArr=[self.clockSettingTable visibleCells];
                UITableViewCell *cell0=[cellArr objectAtIndex:0];
                cell0.accessoryType=UITableViewCellAccessoryCheckmark;
            }
            model.openWeek=YES;
            
        } else {
            [UIView animateWithDuration:0.2 animations:^{
                self.clockSettingTable.frame=CGRectMake(0, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), CGRectGetWidth(self.clockTableView1.frame), 0);
                self.clockSettingTable.alpha=0;
                self.clockTableView2.frame=CGRectMake(0, self.clockSettingTable.frame.origin.y, self.clockTableView2.frame.size.width, 50*2);
                [[self.view viewWithTag:888] viewWithTag:901].alpha=1;
                [[self.view viewWithTag:888] viewWithTag:902].alpha=1;
            }];
            
            model.openWeek=NO;
        }
        
    } else if (self.clockTableView2==tableView){
        
        
    } else if (self.clockSettingTable==tableView){
        SXModel *model=[SXModel shareModel];
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        BOOL same=NO;
        int index=0;
        if (model.weekArr.count>0) {
            for (int i=0; i<model.weekArr.count; i++) {
                NSString *str=[model.weekArr objectAtIndex:i];
                if ([str isEqualToString:cell.textLabel.text]) {
                    same=YES;
                    index=i;
                    break;
                }
            }
        }
        if (!same) {
            cell.accessoryType=UITableViewCellAccessoryCheckmark;
            [model.weekArr addObject:cell.textLabel.text];
            [model.weekIndexArr addObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
        } else {
            cell.accessoryType=UITableViewCellAccessoryNone;
            [model.weekArr removeObjectAtIndex:index];
            [model.weekIndexArr removeObjectAtIndex:index];
        }
        
        if (model.weekArr.count>1 && model.weekArr.count==model.weekIndexArr.count) {
            for (int i=0; i<model.weekIndexArr.count; i++) {
                int index=[[model.weekIndexArr objectAtIndex:i] intValue];
                for (int j=i+1; j<model.weekIndexArr.count; j++) {
                    int comp=[[model.weekIndexArr objectAtIndex:j] intValue];
                    if (index>=comp) {
                        [model.weekIndexArr exchangeObjectAtIndex:i withObjectAtIndex:j];
                        [model.weekArr exchangeObjectAtIndex:i withObjectAtIndex:j];
                    }
                }
            }
        }
        
        [self.clockTableView1 reloadData];
        
        NSLog(@"did select: weekArr=%@",model.weekArr);
        
    }
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.clockTable) {
        if (editingStyle==UITableViewCellEditingStyleDelete) {
            SXModel *model=[SXModel shareModel];
            model.deleteIndex=(int)indexPath.row;
            
            [self deleteClock];
        }
    }
}

#pragma mark - UISwitch
- (void)sleepAWhile:(UISwitch *)sender
{
    self.sleep=sender.on;
}

- (void)onOrOff:(UISwitch *)sender
{
    SXModel *model=[SXModel shareModel];
    
    UITableViewCell *cell=[[self.clockTable visibleCells] objectAtIndex:sender.tag-999];
    NSMutableArray *arr=(NSMutableArray *)[model.localNotiArr objectAtIndex:sender.tag-999];
    NSMutableArray *arrC=[[NSMutableArray alloc] init];
    if (!sender.on) {
        cell.textLabel.textColor=[UIColor grayColor];
        cell.detailTextLabel.textColor=[UIColor grayColor];
        
        
        for (int i=0;i<arr.count; i++) {
            NSMutableDictionary *dic=(NSMutableDictionary *)[arr objectAtIndex:i];
            NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
            UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
            [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
            NSMutableDictionary *changeDic=[NSMutableDictionary dictionaryWithDictionary:dic];
            [changeDic setValue:@"NO" forKey:@"ONOFF"];
            [arrC addObject:changeDic];
            //NSLog(@"Dic=%@",dic);
        }
        
    } else if (sender.on) {
        cell.textLabel.textColor=[self colorWithHexString:@"#9E59E4"];
        cell.detailTextLabel.textColor=[UIColor blackColor];
        
        for (int i=0;i<arr.count; i++) {
            NSMutableDictionary *dic=(NSMutableDictionary *)[arr objectAtIndex:i];
            NSData *data=(NSData *)[dic valueForKey:@"NOTI"];
            UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];
            [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
            NSMutableDictionary *changeDic=[NSMutableDictionary dictionaryWithDictionary:dic];
            [changeDic setValue:@"YES" forKey:@"ONOFF"];
            [arrC addObject:changeDic];
            //NSLog(@"Dic=%@",dic);
        }
        
        
    }
    
    [model.localNotiArr removeObjectAtIndex:sender.tag-999];
    [model.localNotiArr insertObject:arrC atIndex:sender.tag-999];
    NSLog(@"%@",model.localNotiArr);
    NSLog(@"systemLocalNoti=%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
    [[NSUserDefaults standardUserDefaults] setObject:model.localNotiArr forKey:@"NOTIARR"];
    
    
}

- (void)selectMethod:(UIButton *)button
{
    for (int i=500; i<504; i++) {
        UILabel *label=(UILabel *)[[[button superview] superview] viewWithTag:i];
        label.textColor=[UIColor grayColor];
    }
    
    ((UILabel *)[button superview]).textColor=[self colorWithHexString:@"#9E59E4"];
    
    int selectedIndex = (int)button.tag-600;
    
    NSLog(@"%d",selectedIndex);
    self.segIndex=selectedIndex;
    SXModel *model=[SXModel shareModel];
    
    switch (selectedIndex) {
        case 0:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            model.clickedNo=YES;
            
        }
            break;
        case 1:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=0; i<self.weekSArr.count; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
        case 2:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=0; i<self.weekSArr.count-2; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
        case 3:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=5; i<self.weekSArr.count; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
        default:
            break;
    }
    
    [self.clockTableView1 reloadData];
    NSLog(@"valueModelWeekArr=%@",model.weekArr);
    NSLog(@"valueModelWeekIndexArr=%@",model.weekIndexArr);
    NSLog(@"selfSegIndex=%d",self.segIndex);
}

- (void)selectWeek:(UIButton *)button
{
    SXModel *model=[SXModel shareModel];
    
    NSLog(@"weekArrBef=%@",model.weekArr);
    NSLog(@"weekIndexArrBef=%@",model.weekIndexArr);
    BOOL same=NO;
    int index=0;
    if (model.weekArr.count>0) {
        for (int i=0; i<model.weekArr.count; i++) {
            NSString *str=[model.weekArr objectAtIndex:i];
            if ([str isEqualToString:button.titleLabel.text]) {
                same=YES;
                index=i;
                break;
            }
        }
    }
    if (!same) {
        [button setTitleColor:[self colorWithHexString:@"#9E59E4"] forState:UIControlStateNormal];
        [model.weekArr addObject:button.titleLabel.text];
        [model.weekIndexArr addObject:[NSString stringWithFormat:@"%ld",((long)button.tag-300)]];
    } else {
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [model.weekArr removeObjectAtIndex:index];
        [model.weekIndexArr removeObjectAtIndex:index];
    }
    
    if (model.weekArr.count>1 && model.weekArr.count==model.weekIndexArr.count) {
        for (int i=0; i<model.weekIndexArr.count; i++) {
            int index=[[model.weekIndexArr objectAtIndex:i] intValue];
            for (int j=i+1; j<model.weekIndexArr.count; j++) {
                int comp=[[model.weekIndexArr objectAtIndex:j] intValue];
                if (index>=comp) {
                    [model.weekIndexArr exchangeObjectAtIndex:i withObjectAtIndex:j];
                    [model.weekArr exchangeObjectAtIndex:i withObjectAtIndex:j];
                }
            }
        }
    }
    
    NSLog(@"weekArrAft=%@",model.weekArr);
    NSLog(@"weekIndexArrAft=%@",model.weekIndexArr);
    if (model.weekIndexArr.count==0) {
        //[_seg setSelected:YES];
        self.segIndex=0;
    } else {
        
        if ([model.weekIndexArr containsObject:@"1"] && [model.weekIndexArr containsObject:@"2"] && [model.weekIndexArr containsObject:@"3"] && [model.weekIndexArr containsObject:@"4"] &&[model.weekIndexArr containsObject:@"0"] && [model.weekIndexArr containsObject:@"5"] && [model.weekIndexArr containsObject:@"6"]) {
            [_seg setSelected:YES];
            self.segIndex=1;
            
        } else if ([model.weekIndexArr containsObject:@"1"] && [model.weekIndexArr containsObject:@"2"] && [model.weekIndexArr containsObject:@"3"] && [model.weekIndexArr containsObject:@"4"] &&[model.weekIndexArr containsObject:@"0"] && ![model.weekIndexArr containsObject:@"5"] && ![model.weekIndexArr containsObject:@"6"]) {
            //[_seg setSelected:YES];
            self.segIndex=2;
            
        } else if (![model.weekIndexArr containsObject:@"1"] && ![model.weekIndexArr containsObject:@"2"] && ![model.weekIndexArr containsObject:@"3"] && ![model.weekIndexArr containsObject:@"4"] && ![model.weekIndexArr containsObject:@"0"] && [model.weekIndexArr containsObject:@"5"] && [model.weekIndexArr containsObject:@"6"]) {
            //[_seg setSelected:YES];
            self.segIndex=3;
            
        } else
            self.segIndex=5;
    }
    
    NSLog(@"selfSegIndex=%d",self.segIndex);
    [self.clockTableView1 reloadData];
    
}

#pragma mark - UISegmentControl
- (void)controlPressed:(UISegmentedControl *)sender
{
    int selectedIndex = (int)[sender selectedSegmentIndex];
    NSLog(@"%d",selectedIndex);
    SXModel *model=[SXModel shareModel];
//    if (model.openWeek) {
//        [UIView animateWithDuration:0.2 animations:^{
//            self.clockSettingTable.frame=CGRectMake(0, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), CGRectGetWidth(self.clockTableView1.frame), 0);
//            self.clockSettingTable.alpha=0;
//            self.clockTableView2.frame=CGRectMake(0, self.clockSettingTable.frame.origin.y, self.clockTableView2.frame.size.width, 50*2);
//            [[self.view viewWithTag:888] viewWithTag:901].alpha=1;
//            [[self.view viewWithTag:888] viewWithTag:902].alpha=1;
//        }];
//        
//        model.openWeek=NO;
//    }
    switch (selectedIndex) {
        case 0:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            model.clickedNo=YES;
            
        }
            break;
        case 1:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=0; i<self.weekSArr.count; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
        case 2:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=0; i<self.weekSArr.count-2; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
        case 3:{
            model.weekArr=[[NSMutableArray alloc] init];
            model.weekIndexArr=[[NSMutableArray alloc] init];
            [model.weekArr removeAllObjects];
            [model.weekIndexArr removeAllObjects];
            NSMutableArray *arr=[[NSMutableArray alloc] init];
            for (int i=5; i<self.weekSArr.count; i++) {
                NSString *str=[self.weekSArr objectAtIndex:i];
                [model.weekArr addObject:str];
                [arr addObject:[NSString stringWithFormat:@"%d",i]];
                model.weekIndexArr=arr;
            }
        }
            break;
//        case 4:{
//            
//            SXModel *model=[SXModel shareModel];
//            if (!model.openWeek) {
//                CGRect frame=self.clockSettingTable.frame;
//                self.clockSettingTable.alpha=0;
//                [UIView animateWithDuration:0.2 animations:^{
//                    self.clockSettingTable.alpha=1;
//                    [self.clockSettingTable reloadData];
//                    self.clockSettingTable.frame=CGRectMake(0, frame.origin.y, frame.size.width, 50*7);
//                    self.clockTableView2.frame=CGRectMake(0, frame.origin.y+50*7, frame.size.width, 50*2);
//                    [[self.view viewWithTag:888] viewWithTag:901].alpha=0;
//                    [[self.view viewWithTag:888] viewWithTag:902].alpha=0;
//                }];
//                
//                if (model.weekArr.count==7) {
//                    NSArray *cellArr=[self.clockSettingTable visibleCells];
//                    UITableViewCell *cell0=[cellArr objectAtIndex:0];
//                    cell0.accessoryType=UITableViewCellAccessoryCheckmark;
//                }
//                model.openWeek=YES;
//                
//            } else {
//                [UIView animateWithDuration:0.2 animations:^{
//                    self.clockSettingTable.frame=CGRectMake(0, self.clockTableView1.frame.origin.y+CGRectGetHeight(self.clockTableView1.frame), CGRectGetWidth(self.clockTableView1.frame), 0);
//                    self.clockSettingTable.alpha=0;
//                    self.clockTableView2.frame=CGRectMake(0, self.clockSettingTable.frame.origin.y, self.clockTableView2.frame.size.width, 50*2);
//                    [[self.view viewWithTag:888] viewWithTag:901].alpha=1;
//                    [[self.view viewWithTag:888] viewWithTag:902].alpha=1;
//                }];
//                
//                model.openWeek=NO;
//            }
//        }
//            break;
        default:
            break;
    }
    
    [self.clockTableView1 reloadData];
    NSLog(@"valueModelWeekArr=%@",model.weekArr);
    NSLog(@"valueModelWeekIndexArr=%@",model.weekIndexArr);
}

#pragma mark - 过滤动作

#pragma mark - FilterViewDelegate

-(void)actionWithOK:(NSString*)str
{
    filerDetailView = nil;
    self.rightBtn.hidden = NO;
}
-(void)actionWithCancel
{
    filerDetailView = nil;
    self.rightBtn.hidden = NO;
}

-(void)actionWithSubmenuType:(FilterSubmenuType)m_fst withFilterType:(FilterType)m_ft
{
    //NSLog(@"================ actionWithSubmenuType");
    FilterView *filerView = (FilterView*)[self.view viewWithTag:13];
    filerView.level1ViewBG.hidden = YES;
    
    filerView.rubbishBtn.hidden=YES;
    
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FilterLevel2View" owner:self options:nil];
    FilterLevel2View * filterLevel2View = [nib objectAtIndex:0];
    filterLevel2View.bgView.layer.masksToBounds = YES;
    filterLevel2View.bgView.layer.cornerRadius = DefaultCornerRadius;
    [filterLevel2View.bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(homeBackToLevel1:)]];
    filterLevel2View.tag = 14;
    
    for (UIView *view in [filterLevel2View subviews]) {
        if (view.frame.origin.y==50) {
            [view removeFromSuperview];
            break;
        }
    }

    filterLevel2View.frame = CGRectMake(10, 170, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
    filterLevel2View.alpha=0;
    
    CGRect btnFrame=filterLevel2View.backbtn.frame;
    filterLevel2View.backbtn.frame=CGRectMake(100, btnFrame.origin.y, btnFrame.size.width+100, btnFrame.size.height);
    
    [filterLevel2View.backbtn addTarget:self action:@selector(homeBackToLevel1:) forControlEvents:UIControlEventTouchUpInside];
    
    self.m_fst=m_fst;
    filterLevel2View.layer.masksToBounds = YES;
    filterLevel2View.layer.cornerRadius = DefaultCornerRadius;
    
//    UIView *blackStr=[[UIView alloc] init];
//    blackStr.backgroundColor=[UIColor colorWithRed:0 green:0 blue:55.0/255.0 alpha:1];
//    blackStr.frame=CGRectMake(4, 50, filterLevel2View.frame.size.width-8, 1);
//    [filterLevel2View addSubview:blackStr];
    
    m_filtertype = m_ft;
    m_filterSubmenutype = m_fst;
    switch (m_fst) {
        case EM_FST_Chunseban:
        {
            filterLevel2View.titleName.text = @"纯色板";
            
            UIImage *imageChunse=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"chunseban@2x" ofType:@"png"]];
            UIImage *chunsebanImage=imageChunse;
            filterLevel2View.imageView.image = chunsebanImage;
//            self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",
//                                             @"6.png",@"7.png",@"8.png",@"9.png",
//                                             @"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png",
//                                             @"16.png",nil];
            self.filterLevel3CV.backgroundColor = BGColor;
            self.filterLevel3CV.alpha=0;
            
            SXModel *model=[SXModel shareModel];
            if (model.touming || model.chunseban || model.zhuseban || model.peiseban || model.wuzhuseban) {
                self.filterLevel3CV.frame=CGRectMake(self.filterLevel3CV.frame.origin.x, self.filterLevel3CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel3CV.frame), CGRectGetHeight(self.filterLevel3CV.frame));
                model.chunseban=NO;
            }
            CGRect cvframe=self.filterLevel3CV.frame;
            self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel3CV];
            [filerView addSubview:filterLevel2View];
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png", nil];
                    [self.filterLevel3CV reloadData];
                    
                    self.filterLevel3CV.alpha=1;
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 50);
                    
                    [self.filterLevel2CVinfoArrays addObject:@"5.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"6.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"7.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"8.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 100);
                    [self.filterLevel2CVinfoArrays addObject:@"9.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"10.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"11.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"12.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 150);
                    [self.filterLevel2CVinfoArrays addObject:@"13.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"14.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"15.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"16.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 200);
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.chunseban=YES;
            }];
            
        }
            break;
            
        case EM_FST_Kuanshi:
        {
            kuanshi1tvChoiceKey = nil;
            filterLevel2View.titleName.text = @"款式细节";
            
            UIImage *imageKuanshi=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"kuanshi@2x" ofType:@"png"]];
            filterLevel2View.imageView.image = imageKuanshi;
            //self.kuanshi1OutTimes=6;
            [self dataFromDBToKS1];
            self.kuanshi1tv.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.kuanshi) {
                self.kuanshi1tv.frame=CGRectMake(self.kuanshi1tv.frame.origin.x, self.kuanshi1tv.frame.origin.y-6, self.kuanshi1tv.frame.size.width, self.kuanshi1tv.frame.size.height);
                model.kuanshi=NO;
            }
            CGRect kuanshi1Frame=self.kuanshi1tv.frame;
            self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 0);
            [filterLevel2View addSubview:self.kuanshi1tv];
            [filerView addSubview:filterLevel2View];
            filterViewType = EM_FVT_top2;
//            //取出现有所有行的数据
//            NSMutableArray *dataArr=[[NSMutableArray alloc] init];
//            NSLog(@"kuanshirows%ld",(long)[self.kuanshi1tv numberOfRowsInSection:0]);
//            for (int i=0; i<[self.kuanshi1tv numberOfRowsInSection:0]; i++) {
//                [dataArr addObject:[self.kuanshi1tv cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]].textLabel.text];
//            }
//            //删掉现有的所有行
//            NSMutableArray *indexs=[[NSMutableArray alloc] init];
//            for (int i=0; i<[self.kuanshi1tv numberOfRowsInSection:0]; i++) {
//                [indexs addObject:[NSIndexPath indexPathForRow:i inSection:0]];
//            }
//            [self.kuanshi1tv deleteRowsAtIndexPaths:indexs withRowAnimation:UITableViewRowAnimationNone];
           
            
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.kuanshi1tv.alpha=1;
                    self.kuanshi1OutTimes=5;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44);
                    [self.kuanshi1tv reloadData];
                    self.kuanshi1OutTimes=4;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44*2);
                    [self.kuanshi1tv reloadData];
                    self.kuanshi1OutTimes=3;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44*3);
                    [self.kuanshi1tv reloadData];
                    self.kuanshi1OutTimes=2;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44*4);
                    [self.kuanshi1tv reloadData];
                    self.kuanshi1OutTimes=1;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44*4);
                    [self.kuanshi1tv reloadData];
                    self.kuanshi1OutTimes=0;
                    self.kuanshi1tv.frame=CGRectMake(0, kuanshi1Frame.origin.y+6, kuanshi1Frame.size.width, 44*4);
                    [self.kuanshi1tv reloadData];
                    
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.kuanshi=YES;
                self.kuanshi1tv.scrollEnabled=NO;
            }];
            
        }
            break;
            
        case EM_FST_Peiseban:
        {
            filterLevel2View.titleName.text = @"配色板";
            UIImage *imagePeise=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"peisheban@2x" ofType:@"png"]];
            filterLevel2View.imageView.image = imagePeise;
            [self.filterLevel2CVinfoArrays removeAllObjects];
            self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png",@"w5.png",
                                             @"w6.png",@"w7.png",@"w8.png",@"w9.png",
                                             @"w10.png",@"w11.png",@"w12.png",@"w13.png",nil];
            self.filterLevel3CV.backgroundColor = BGColor;
            self.filterLevel3CV.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.touming || model.chunseban || model.zhuseban || model.peiseban || model.wuzhuseban) {
                self.filterLevel3CV.frame=CGRectMake(self.filterLevel3CV.frame.origin.x, self.filterLevel3CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel3CV.frame), CGRectGetHeight(self.filterLevel3CV.frame));
                model.peiseban=NO;
            }
            CGRect cvframe=self.filterLevel3CV.frame;
            self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel3CV];
            [filerView addSubview:filterLevel2View];
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png", nil];
                    [self.filterLevel3CV reloadData];
                    
                    self.filterLevel3CV.alpha=1;
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 50);
                    
                    [self.filterLevel2CVinfoArrays addObject:@"w5.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w6.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w7.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w8.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 100);
                    [self.filterLevel2CVinfoArrays addObject:@"w9.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w10.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w11.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w12.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 150);
                    [self.filterLevel2CVinfoArrays addObject:@"w13.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 200);
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.peiseban=YES;
            }];
            
            //[Utility showHelpWith:@"help6@2x.png"];
        }
            break;
        case EM_FST_Zhuseban:
        {
            filterLevel2View.titleName.text = @"主色板";
            UIImage *imageZhuse=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zhuseban@2x" ofType:@"png"]];
            filterLevel2View.imageView.image = imageZhuse;
            self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",
                                             @"6.png",@"7.png",@"8.png",@"9.png",
                                             @"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png",
                                             @"16.png",nil];
            self.filterLevel3CV.backgroundColor = BGColor;
            self.filterLevel3CV.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.touming || model.chunseban || model.zhuseban || model.peiseban || model.wuzhuseban) {
                self.filterLevel3CV.frame=CGRectMake(self.filterLevel3CV.frame.origin.x, self.filterLevel3CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel3CV.frame), CGRectGetHeight(self.filterLevel3CV.frame));
                model.zhuseban=NO;
            }
            CGRect cvframe=self.filterLevel3CV.frame;
            self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel3CV];
            [filerView addSubview:filterLevel2View];
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png", nil];
                    [self.filterLevel3CV reloadData];
                    
                    self.filterLevel3CV.alpha=1;
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 50);
                    
                    [self.filterLevel2CVinfoArrays addObject:@"5.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"6.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"7.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"8.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 100);
                    [self.filterLevel2CVinfoArrays addObject:@"9.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"10.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"11.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"12.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 150);
                    [self.filterLevel2CVinfoArrays addObject:@"13.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"14.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"15.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"16.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 200);
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.zhuseban=YES;
            }];
            
        }
            break;
        case EM_FST_wZhuseban:
        {
            filterLevel2View.titleName.text = @"主色板";
            filterLevel2View.imageView.image = [UIImage imageNamed:@"zhuseban.png"];
            self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png",@"w5.png",
                                             @"w6.png",@"w7.png",@"w8.png",@"w9.png",
                                             @"w10.png",@"w11.png",@"w12.png",@"w13.png",nil];
            self.filterLevel3CV.backgroundColor = BGColor;
            self.filterLevel3CV.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.touming || model.chunseban || model.zhuseban || model.peiseban || model.wuzhuseban) {
                self.filterLevel3CV.frame=CGRectMake(self.filterLevel3CV.frame.origin.x, self.filterLevel3CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel3CV.frame), CGRectGetHeight(self.filterLevel3CV.frame));
                model.wuzhuseban=NO;
            }
            CGRect cvframe=self.filterLevel3CV.frame;
            self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel3CV];
            [filerView addSubview:filterLevel2View];
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png", nil];
                    [self.filterLevel3CV reloadData];
                    
                    self.filterLevel3CV.alpha=1;
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 50);
                    
                    [self.filterLevel2CVinfoArrays addObject:@"w5.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w6.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w7.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w8.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 100);
                    [self.filterLevel2CVinfoArrays addObject:@"w9.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w10.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w11.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w12.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 150);
                    [self.filterLevel2CVinfoArrays addObject:@"w13.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 200);
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.wuzhuseban=YES;
            }];
            //[Utility showHelpWith:@"help6@2x.png"];
        
        }
            break;
        case EM_FST_YanSeshuxing:
        {
            filterLevel2View.titleName.text = @"颜色属性";
            filterLevel2View.imageView.image = [UIImage imageNamed:@"yansheshuxing.png"];

            [self dataFromDBYanseWith:m_filtertype];
            self.filterLevel2CV.backgroundColor = BGColor;
            
            self.filterLevel2CV.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.yanseshuxing) {
                self.filterLevel2CV.frame=CGRectMake(self.filterLevel2CV.frame.origin.x, self.filterLevel2CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel2CV.frame), CGRectGetHeight(self.filterLevel2CV.frame));
                model.yanseshuxing=NO;
            }
            
            CGRect cvframe=self.filterLevel2CV.frame;
            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel2CV];
            [filerView addSubview:filterLevel2View];
            
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                switch (m_filtertype) {
                    case 1:
                    {
//                        self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"yssx_jubu.png",@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png",@"yssx_bandian.png",@"yssx_huaxi.png",@"yssx_qita.png",@"yssx_jianbian.png",@"yssx_wenzi.png",@"yssx_logo.png",@"yssx_zase.png",@"yssx_bopu.png",@"yssx_miaobian.png",nil];
                        [UIView animateWithDuration:0.2 animations:^{
                            SXModel *model=[SXModel shareModel];
                            if (!model.juBuPeiSe) {
                                self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png", nil];
                            } else if (model.juBuPeiSe){
                                self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"yssx_jubu.png",@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png", nil];
                            }
                            
                            [self.filterLevel2CV reloadData];
                            
                            self.filterLevel2CV.alpha=1;
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 60);
                            
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_bandian.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_huaxi.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_qita.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_jianbian.png"];
                            [self.filterLevel2CV reloadData];
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 120);
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_wenzi.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_logo.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_zase.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_bopu.png"];
                            [self.filterLevel2CV reloadData];
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 180);
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_miaobian.png"];
                            [self.filterLevel2CV reloadData];
                            if (!model.juBuPeiSe) {
                                self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 190);
                            } else
                                self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 240);
                            
                        }];
                    }
                        break;
                    case 2:
                    {
//                        self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"yssx_jubu.png",@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png",@"yssx_bandian.png",@"yssx_huaxi.png",@"yssx_baowen.png",@"yssx_feiniao.png",@"yssx_zase.png",@"yssx_jianbian.png",@"yssx_bopu.png",@"yssx_micai.png",nil];
                        
                        [UIView animateWithDuration:0.2 animations:^{
                            SXModel *model=[SXModel shareModel];
                            if (!model.juBuPeiSe) {
                                self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png", nil];
                            } else if (model.juBuPeiSe){
                                self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"yssx_jubu.png",@"yssx_pinse.png",@"yssx_gezi.png",@"yssx_tiaowen.png", nil];
                            }
                            
                            [self.filterLevel2CV reloadData];
                            
                            self.filterLevel2CV.alpha=1;
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 60);
                            
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_bandian.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_huaxi.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_baowen.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_feiniao.png"];
                            [self.filterLevel2CV reloadData];
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 120);
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_zase.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_jianbian.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_bopu.png"];
                            [self.filterLevel2CVinfoArrays addObject:@"yssx_micai.png"];
                            [self.filterLevel2CV reloadData];
                            self.filterLevel2CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 190);
                            
                        }];
                    }
                        break;
                    default:
                        break;
                }

                
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.yanseshuxing=YES;
            }];
//            if (self.iPhone) {
//                //[Utility showHelpWith:@"help7-4s@2x.png"];
//            } else
//                //[Utility showHelpWith:@"help7.png"];
        }
            break;
            
        case EM_FST_touMingSeban:
        {
            filterLevel2View.titleName.text = @"透明色";
            filterLevel2View.imageView.image = [UIImage imageNamed:@"w_si.png"];
            self.filterLevel2CVinfoArrays = [[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png",@"w5.png",
                                             @"w6.png",@"w7.png",@"w8.png",@"w9.png",@"w11.png",@"w13.png",nil];
            self.filterLevel3CV.backgroundColor = BGColor;
            self.filterLevel3CV.alpha=0;
            SXModel *model=[SXModel shareModel];
            if (model.touming || model.chunseban || model.zhuseban || model.peiseban || model.wuzhuseban) {
                self.filterLevel3CV.frame=CGRectMake(self.filterLevel3CV.frame.origin.x, self.filterLevel3CV.frame.origin.y-6, CGRectGetWidth(self.filterLevel3CV.frame), CGRectGetHeight(self.filterLevel3CV.frame));
                model.touming=NO;
            }
            
            CGRect cvframe=self.filterLevel3CV.frame;
            self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 0);
            [filterLevel2View addSubview:self.filterLevel3CV];
            [filerView addSubview:filterLevel2View];
            [UIView animateWithDuration:0.2 animations:^{
                filterLevel2View.alpha=1;
                filterLevel2View.frame = CGRectMake(10, 114, filterLevel2View.frame.size.width, filterLevel2View.frame.size.height);
                filterViewType = EM_FVT_top2;
                
                [UIView animateWithDuration:0.2 animations:^{
                    self.filterLevel2CVinfoArrays=[[NSMutableArray alloc] initWithObjects:@"w1.png",@"w2.png",@"w3.png",@"w4.png", nil];
                    [self.filterLevel3CV reloadData];
                    
                    self.filterLevel3CV.alpha=1;
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 50);
                    
                    [self.filterLevel2CVinfoArrays addObject:@"w5.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w6.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w7.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w8.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 100);
                    [self.filterLevel2CVinfoArrays addObject:@"w9.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w10.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w11.png"];
                    [self.filterLevel2CVinfoArrays addObject:@"w12.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 150);
                    [self.filterLevel2CVinfoArrays addObject:@"w13.png"];
                    [self.filterLevel3CV reloadData];
                    self.filterLevel3CV.frame=CGRectMake(0, cvframe.origin.y+6, cvframe.size.width, 200);
                }];
            } completion:^(BOOL finished) {
                SXModel *model=[SXModel shareModel];
                model.touming=YES;
            }];
        }
            break;
        default:
            break;
    }
}


-(void)actionDeleteClothes
{
    if ([SearchDic count]==0) {
        if (filerDetailView) {
            [filerDetailView removeFromSuperview];
            filerDetailView = nil;
            isHomeSearch = YES;
            filerBtn.alpha = 0.f;
            viewType = EM_VT_Home;
            self.leftBtn.hidden=YES;
            [[self.leftBtn viewWithTag:200] removeFromSuperview];
            //[self.leftBtn setImage:[UIImage imageNamed:@"home_history_icon.png"] forState:UIControlStateNormal];
            [[self.navigationController.navigationBar viewWithTag:900] removeFromSuperview];
            [[self.navigationController.navigationBar viewWithTag:300] removeFromSuperview];
            [[self.rightBtn viewWithTag:100] removeFromSuperview];
            [self.rightBtn setImage:[UIImage imageNamed:@"home_find.png"] forState:UIControlStateNormal];
            [self addRefresh];
            isNewSearch=YES;
            
            SXModel *model=[SXModel shareModel];
            model.searched=NO;
            [model.clothesItemArr removeAllObjects];
            model.createKuanshi=NO;
            //model.isKuanshi=NO;
            model.createPeise=NO;
            model.createTuan=NO;
            model.tuanAction=NO;
            model.peiseAction=NO;
            model.sebanIndex=0;
            model.befIndex=0;
            model.anoIndex=0;
            [model.selectedTuanDic removeAllObjects];
            [model.selectedPeiseDic removeAllObjects];
            [self refreshView];
        }
    }
}

- (void)backToHome
{
    isHomeSearch = YES;
    filerBtn.alpha = 0.f;
    viewType = EM_VT_Home;
    self.leftBtn.hidden=YES;
    [[self.leftBtn viewWithTag:200] removeFromSuperview];
    //[self.leftBtn setImage:[UIImage imageNamed:@"home_history_icon.png"] forState:UIControlStateNormal];
    [[self.rightBtn viewWithTag:100] removeFromSuperview];
    [self.rightBtn setImage:[UIImage imageNamed:@"home_find.png"] forState:UIControlStateNormal];
    [[self.navigationController.navigationBar viewWithTag:900] removeFromSuperview];
    [[self.navigationController.navigationBar viewWithTag:300] removeFromSuperview];
    [self addRefresh];
    isNewSearch=YES;
    
    SXModel *model=[SXModel shareModel];
    model.searched=NO;
    [model.clothesItemArr removeAllObjects];
    model.createKuanshi=NO;
    //model.isKuanshi=NO;
    model.createPeise=NO;
    model.createTuan=NO;
    model.tuanAction=NO;
    model.peiseAction=NO;
    model.sebanIndex=0;
    model.befIndex=0;
    model.anoIndex=0;
    [model.selectedTuanDic removeAllObjects];
    [model.selectedPeiseDic removeAllObjects];
    [self refreshView];
}

#pragma mark - UITouch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:filerDetailView];
    
    if (self.filterLevel4CV.alpha==1) {
        if (touchPoint.y<self.scroll3CVView.frame.origin.y || touchPoint.y>self.scroll3CVView.frame.size.height+self.scroll3CVView.frame.origin.y) {
            [self backToZhuseban];
        }
    }
    
//    if (<#condition#>) {
//        <#statements#>
//    }
//    CGMutablePathRef pathRef=CGPathCreateMutable();
//    if (!CGPathContainsPoint(pathRef, NULL, touchPoint, NO)) {
//        
//    }
    
}

#pragma mark - filterview btn action

-(IBAction)homeBackToLevel1:(FilterSubmenuType)m_fst
{
    FilterView *filerView = (FilterView*)[self.view viewWithTag:13];
    filerView.level1ViewBG.hidden = NO;
    //filerView.level1ViewBG.alpha=0;
    filerView.rubbishBtn.hidden=NO;
    
    FilterLevel2View * filterLevel2View = (FilterLevel2View *)[filerView viewWithTag:14];
    [UIView animateWithDuration:0.2 animations:^{
        filterLevel2View.alpha=0;
        [filerView reloadInfo];
    } completion:^(BOOL finished) {
        [filterLevel2View removeFromSuperview];
    }];
    
}

- (void)backToZhuseban
{
//    [_leftArrow removeFromSuperview];
//    [_rightArrow removeFromSuperview];
    
    
    //[self refreshFilterLevel3CV];
    FilterView *filerView = (FilterView*)[self.view viewWithTag:13];
    [filerView removeGestureRecognizer:_swipeR];
    [filerView removeGestureRecognizer:_swipeL];
    
    self.scroll3CVView.alpha=1;
    self.scroll3CVView.scrollEnabled=YES;
    [self.filterLevel4CV removeFromSuperview];
    
    if (m_filterSubmenutype==EM_FST_Chunseban) {
        self.filterLevel3CBef.alpha=1;
        [self.filterLevel3CBef reloadData];
    } else if (m_filterSubmenutype==EM_FST_Zhuseban) {
        self.filterLevel3CV.alpha=1;
        [self.filterLevel3CV reloadData];
    } else if (m_filterSubmenutype==EM_FST_wZhuseban) {
        self.filterLevel3CAno.alpha=1;
        [self.filterLevel3CAno reloadData];
    }
    
    SXModel *model=[SXModel shareModel];
    model.sebanIndex=0;
    model.befIndex=0;
    model.anoIndex=0;
    model.Arrow=NO;
}

@end
